Get last page visited

I need to know if the person who comes to my site got from another specific site. Example:

  • User A visits www.youtube.com/myvideo and clicks a link to my site.
  • User B visits Google, browses my site and clicks on the link.

A message with the results on my page:

  • User A: Welcome! You already know how it works, register now! Welcome! You already know how it works, register now!
  • User B: Welcome! Please watch our video first at www.youtube.com/myvideo Welcome! Please watch our video first at www.youtube.com/myvideo

My question is:

  • Is it possible to find out the last URL that a user visited before entering my page?
    I have already tried $_SERVER['HTTP_REFERER'] with PHP, but it doesnโ€™t work correctly and I read that it doesnโ€™t work in all browsers.
  • Is there any language or php script to get this url while working on the whole browser correctly?
+7
source share
3 answers

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

Please note that this header will work in most cases. Also note that it can be easily faked.

+15
source

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

At your discretion and appearance, you can rewrite the URL to something like www.yoursite.com/youtube

+2
source
 <?php if (strpos($_SERVER['HTTP_REFERER'],'youtube') !== false){ echo 'Welcome! You already know how it works, <a href="/register">register now!</a>'; } else { echo 'Welcome! Please watch our video first at <a href="www.youtube.com/myvideo">www.youtube.com/myvideo</a>'; }?> 
0
source

All Articles