Okay, What is the best method for getting the referer in PHP? HTTP-REFERER should not be used because it can be faked and some firewalls block it.... $_SERVER['REQUEST_URI'] in conjunction with Caudium does not return the full pathway. If someone comes to my website from A google search or comes to my website via another website. What is the best way in PHP to detect that and have the full URL with the query strings, if any? Thanks for any help Wayne
Referrer is the best variable. It can always be faked, but if it is, there is no true way to get what it actually is since it's sent by the client.
Why not do a test screen dump of all the global variables php offers, and see if anything looks like what you need? It's a useful learning experience. <?php $crlf=chr(13).chr(10); $br='<br />'.$crlf; $p='<br /><br />'.$crlf; foreach ($_SERVER as $key => $datum) { echo $key.' : '.$datum.$br; } echo $p; exit; ?> PHP: . . . and the same for the other variables available.
Thank you. I have that already. I read one of your previous posts and copied it from there as well as I have the phpinfo(); I find more information from the phpinfo(); then from the list that comes up with the script however. With script there are some globals missing. Wayne
Getting the referer environment variable is the only way I know. $ENV{'HTTP_REFERER'} To my knowledge, it should have the full URL, with the query strings. If you want it without the querystring, do something like: $myReferer=$ENV{'HTTP_REFERER'}; $myReferer =~ s/\?*//; Note: I have heard that this would be blank if it came from SSL sites. Quote from section 9 of http://httpd.apache.org/docs/misc/FAQ.html "However, it is important to understand that any access restriction based on the REFERER header is intrinsically problematic due to the fact that browsers can send an incorrect REFERER, either because they want to circumvent your restriction or simply because they don't send the right thing (or anything at all)." Robert Fuess Spiderweb Logic
Thats handy. For some reason I never thought of that, was stuck wondering how to use somehting like print_r($_SERVER), but not echo it... damn. thanks
Kind of related I have a 301 referrer that pushes people to a generic 404 page. And in my AwSTATS I can get these to show up as 404, as I have the HTTP header, but I was wondering if I could add the referrers info too? Currently I have in 404.php[/php] <?php header("HTTP/1.1 404 Not Found"); header("Status: 404 Not Found"); ?> <html> <head> <title>404 Page ! blah ... etc PHP: Thanks
Probably because you opened the script directly, not following a link. Then the referrer is not given, so the variable does not exist in your request.