Page 1 of 1

logging the referer (referrer!)

Posted: Thu Oct 05, 2006 4:01 am
by will83
Hi, I have a site where I want to log the refer from visitors entering on any page. I will only be actually collecting this information when someone makes a purchase or sends an enquiry.

I presume I will log it by setting a cookie and then when they submit a sale/enquiry the existence of the cookie is checked and info passed on entered into the DB.

When a user has entered a page from an exernal site and then start browsing around, I obviously don't want my internal pages recorded as the referer so would I then use sessions to let other pages know that a referer has been logged?

I'm just a bit lost and and would like to see how anyone else has done it??

cheers, Will.

Posted: Thu Oct 05, 2006 4:17 am
by timvw
Everytime there is a $_SERVER['HTTP_REFERER'] value that does not originate from your site, store it in the $_SESSION['referer']. Now, you'll always know what the last external site was (if their browser actually passes the referer header and if there was an external site).

Posted: Thu Oct 05, 2006 5:09 am
by will83
Thank you!

Posted: Thu Oct 05, 2006 7:20 am
by will83
Sorry, which method would you use for testing if the referal was frm my site. Test the url for my site address or something to do with ip?


Thanks again.

Posted: Fri Oct 06, 2006 1:40 am
by RobertGonzalez
The server variable HTTP_REFERER is not a reliable value as it is not always sent with the response headers.

Posted: Fri Oct 06, 2006 10:01 am
by Dave2000
Can you suggest a more reliable alternative?

Posted: Fri Oct 06, 2006 10:20 am
by RobertGonzalez
There isn't really a reliable method, save for a session var of some sort. When I have absolutely needed a page to know that it was requested from my site I put a check in for a session var. If the var is not set send the user to a page within my domain, otherwise show 'em what they wanted.