Know from where my page was accessed

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
konkivo
Forum Newbie
Posts: 2
Joined: Wed Jul 08, 2009 12:04 pm

Know from where my page was accessed

Post by konkivo »

Hi! I'm new in PHP and I wanted to know if it's possible to know from where my page has been called?

My company wants to show different information depending if the client accessed the page from google, from another link, typing directly, etc... is there a way to keep track of this?

Thank you so much!!!
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: Know from where my page was accessed

Post by superdezign »

Yes it is, but doing so in a reliable way is nearly impossible. You would use the server variable HTTP_REFERER, which can be located in PHP via the $_SERVER array as $_SERVER['HTTP_REFERER']. However, the client's browser must send this variable to your server, and many of your more web-savvy users can block this variable from ever being sent. Anonymity on the internet is desirable, so many users will do this, myself included. So, you will have requests from other websites that will seem as if they accessed your website directly.

If you want to know where users are navigating from within your own website, you could place the location into the url in the query string. For example, on your Contact page, every link could have the query string, "?ref=contact", tacked to the end of them.
konkivo
Forum Newbie
Posts: 2
Joined: Wed Jul 08, 2009 12:04 pm

Re: Know from where my page was accessed

Post by konkivo »

thank you so much! I'll some research on the matter :)

Thanks!!!
Post Reply