tags:

views:

23

answers:

1

I want to identify from where a visitor coming to my webpage.Is there anyways to getting that reference in a javascript file.eg: if my website is www.example.com.if user getting this site from google or bing search,then i need to identify that,user from google or bing respectivly.How can i get this in javascript(more priority) or in php.If anybody know help me please...

+2  A: 

You want to get the Referer information.

In PHP, you can access it with $_SERVER['HTTP_REFERER'].

In Javascript, I suppose that this should give you that information : document.referrer.


Note : the referer is an information that's sent by the user's browser, which means :

  • It can, or cannot, be sent
    • Which means your application can use it to provide some additionnal stuff,
    • But must work even if the Referer is not there.
  • It can be forged
    • Which means you must not trust it for any important feature.
    • And you might want to filter/validate it
Pascal MARTIN
which is correct but,document.referrer method not working with my browser.i dont know why?I am using firefox.thanks.
Ajith
I just gave it a try, with Firefox, and it worked properly ; are you sure there's a referer sent, in your case ?
Pascal MARTIN