Ricardo Neves
Ricardo Neves

Reputation: 515

Get last page visited

I need to know if a person that comes to my website went from an another specific website. Example:

Results Message on my page:

My question is:

  1. Is it possible to know the last url the user visited before entering my page?
    I already tried $_SERVER['HTTP_REFERER'] with PHP, but it's not working correctly and I read that does not work on all browsers.
  2. Is there any language or php script to get this url, working on all browser correctly?

Upvotes: 10

Views: 33172

Answers (2)

Simon
Simon

Reputation: 143

Why not add a GET variable to the link on youtube - www.yoursite.com/?referrer=youtube

For discretion and appearance you could rewrite the URL to something like www.yoursite.com/youtube

Upvotes: 2

Brad
Brad

Reputation: 163272

The HTTP referer header is the only way. This is the data that is given to you in PHP via $_SERVER['HTTP_REFERER'].

Note that this header will work in most cases. Also note that it can be easily spoofed.

Upvotes: 20

Related Questions