...

View Full Version : Where Visitors Came From



Candrias77
04-22-2003, 05:26 AM
I have code in my 404 page which uses $_SERVER['HTTP_REFERER'] to catch the link that was requested and inserts in into my database so that I can review exactly what broken links people are using.

My problem is that I would like to detect the name of the PAGE that the user came from as well as the LINK that they were looking for.

For example:

I have a page called test.php and it contains a link to http://www.site.com/nosuchpage. The $_SERVER['HTTP_REFERER'] code in the 404 page returns http://www.site.com/nosuchpage. I would also like to be able to record the PAGE that the user came from ie. test.php.

... Hope that that makes sense, let me know if I have not been clear.

Thanks

Spookster
04-22-2003, 07:04 AM
Originally posted by Candrias77
I have a page called test.php and it contains a link to http://www.site.com/nosuchpage. The $_SERVER['HTTP_REFERER'] code in the 404 page returns http://www.site.com/nosuchpage. I would also like to be able to record the PAGE that the user came from ie. test.php.

... Hope that that makes sense, let me know if I have not been clear.

Thanks

HTTP_REFERER will give you the page the user came from not the page they were looking for. If you want the page they were looking for then you would use REQUEST_URI. For example:




<?php
echo "The requested page was: " . $_SERVER["REQUEST_URI"] . "<br>";
echo "The referring page was: " . $_SERVER["HTTP_REFERER"];
?>



You may also want to parse both of those after getting them to strip out everything except for the filename unless of course you want path information.

Candrias77
04-22-2003, 07:23 AM
Originally posted by Spookster
HTTP_REFERER will give you the page the user came from not the page they were looking for. If you want the page they were looking for then you would use REQUEST_URI.

This is what I thought but in practice it is not working for me. I definately get http://www.site.com/nosuchpage (the linked url) when i echo $_SERVER['HTTP_REFERER']. HOWEVER, if I then refresh the 404 page it echoes the referring page, http://www.site.com/test.php :confused:

As mentioned, the code resides in my 404 page (not the host's default). Could it be possible that the method my host is using to redirect a user to the custom 404 is causing the incorrect results?

Spookster
04-22-2003, 07:48 AM
Assuming you are on a Linux server running Apache and you have your 404 page location defined in your .htaccess file then no your host is not doing anything. Apache reads your .htaccess file and anytime a request to Apache ends up with a code 404 then (either redirects to the 404 page you defined or replaces the contents of the missing page with the contents of the 404 page).



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum