I know how to get the URL of what site they're at but not the site title, does anyone know how? This is how I do the URL.
Code:if (!isset($_SERVER['HTTP_REFERER'])) {
$url = "Unknown";
}
else {
$url = $_SERVER['HTTP_REFERER'];
}
Printable View
I know how to get the URL of what site they're at but not the site title, does anyone know how? This is how I do the URL.
Code:if (!isset($_SERVER['HTTP_REFERER'])) {
$url = "Unknown";
}
else {
$url = $_SERVER['HTTP_REFERER'];
}
You will have to load the contents of the URL into an XML document and extract the title element. You must first ensure the Referrer is a url:
PHP Code:if (parse_url($_SERVER['HTTP_REFERER'])) {
$page = new DOMDocument('1.0');
$page->loadHTML(file_get_contents($_SERVER['HTTP_REFERER']));
$title = $page->getElementsByTagName('title')->item(0)->nodeValue;
}
This is what I've done:-
And where it shows:Code:if (!isset($_SERVER['HTTP_REFERER'])) { // Check the url they came from
$url = "Unknown"; // If no URL then show the words Unknown
}
else {
$url = $_SERVER['HTTP_REFERER']; // Shows the URL
$page = new DOMDocument(1.0);
$page->loadHTML(file_get_contents($url));
$title = $pages->getElementsByTagName('title')->item(0)->nodeValue;
}
But it doesn't work.Code:ImageString ($back, 5, 170, 100, "$title", $textcolor);
It doesn't work? Well without more information I could only speculate on why ;)
BTW, you have changed the code. I explained that you MUST check the referer is a URL. Otherwise someone could forge the header and have your script open files on the web server instead of the URL
You should get the message "Call to member function on a non-object". Don't suppress error messages; it makes debugging impossible and wastes your time.
I think opening the referring URL in such a manner is a bad practice, because it results in double the amount of requests for the server hosting the page containing the image (one from the client, and one from the server hosting the dynamic image).
Also, the quotes around $title are superfluous, since $title is a string anyway.
Quote:
Originally Posted by iamme2007
When I remove the quotes around the string I get this "The image “http://localhost:2000/stat%20sig/sig.php” cannot be displayed, because it contains errors." thats why its there.
And I've found a script that can get the page title but I'm having trouble finding the code that does it, the link:-
http://www.planetsourcecode.com/vb/s...d=356&lngWId=8
The quotes around the string make NO difference. What error does you script produce, how does it not work?
Defiantly, you should at the very least be caching the results.Quote:
Originally Posted by penagate
I've uploaded the complete source, its what I've done so far, I'm new to PHP.
Can someone see why its giving me the error when I remove the strings from the quotes, also try adding the current site title?
Why would you want to remove the quotes? You should not have quotes if you are using a single variable. I.e: "$text" is identical to $text.
If you want someone to do it for you then hire someone. You've been given some example code and some advice on how to do it. So how about you tell us what error you are getting and we go from there?
Tip: remove the Content-Type header from the top of the script while debugging, so you can see the error messages. :)