View Full Version : Http-referer Vs $_server['request_uri']
ProductivePC
May 29th 2004, 5:03 pm
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
digitalpoint
May 29th 2004, 5:04 pm
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.
ProductivePC
May 29th 2004, 5:10 pm
Thanks Shawn
Owlcroft
May 29th 2004, 7:38 pm
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;
?>
. . . and the same for the other variables available.
ProductivePC
May 29th 2004, 8:46 pm
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
rfuess
Jun 15th 2004, 10:30 pm
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 (http://www.spiderweblogic.com)
deadmoon
Aug 26th 2006, 8:34 am
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;
?>
. . . and the same for the other variables available.
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 :D
pablo
Nov 25th 2006, 11:51 pm
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 [b]404.php[/php]
<?php
header("HTTP/1.1 404 Not Found");
header("Status: 404 Not Found");
?>
<html>
<head>
<title>404 Page ! blah ... etc
Thanks
koolasia
Nov 26th 2006, 12:12 am
HTTP-REFERER is better i guess
ForumJoiner
Oct 18th 2007, 3:07 am
When running Owlcroft's PHP code, there is no "referer" word in the entire page. Why?
theOtherOne
Oct 18th 2007, 6:28 am
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.
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.