How to find out where the user is coming from?

Discussion in 'JavaScript' started by KodeKaran, Feb 14, 2011.

  1. #1
    Hi,
    I've been coding up a huge site for the last few months - and I'm adding some extra touches.

    I was wondering how I can determine where the user is coming from (I think this can be done with PHP, but I'm not too sure, I think JavaScript would be more likely), eg - If they Google'd my site, it would show something like "Hello Googler".

    Or if they clicked on a link from the main page, which goes in to a deeper part of the site, they can have a link to return to the main part of the site.

    Does anyone know how to do this?

    Thanks,
    Responses appreciated. :)
     
    KodeKaran, Feb 14, 2011 IP
  2. Cash Nebula

    Cash Nebula Peon

    Messages:
    1,197
    Likes Received:
    67
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You can try using the referrer property but it has many problems.
    <script type='text/javascript'>alert(document.referrer);</script>
    Code (markup):
    It returns nothing for local files and IE apparently. Plus, I think you have to click something on the last page, not use a bookmark or the address bar.
     
    Last edited: Feb 15, 2011
    Cash Nebula, Feb 15, 2011 IP