logging the referer (referrer!)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

logging the referer (referrer!)

Post 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.
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post 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).
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Post by will83 »

Thank you!
User avatar
will83
Forum Commoner
Posts: 53
Joined: Thu Nov 10, 2005 3:13 pm

Post 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.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The server variable HTTP_REFERER is not a reliable value as it is not always sent with the response headers.
Dave2000
Forum Contributor
Posts: 126
Joined: Wed Jun 21, 2006 1:48 pm

Post by Dave2000 »

Can you suggest a more reliable alternative?
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply