Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Tracking original referrer

track first referer to website



12:01 pm on Jul 26, 2009 (gmt 0)

10+ Year Member


I'm no expert in JavaScript, but thought this would be an easy one. After several hours of searching, I've simply ended up totally confused!

My client wants to trace the original/first HTTP referer of every visitor to his site. He wants his home page to write a cookie to the user's computer recording the referer domain. The php-driven inquiry form will then access the cookie and include the refer information in the notification to the client.

I'm not worried about the php side - but am having great trouble finding a reliable source for the JavaScript code to write the initial cookie. I thought this would be literally just a couple of lines of code, but studying the web it seems a lot more complex. Any help would be appreciated.


12:31 am on Jul 27, 2009 (gmt 0)

WebmasterWorld Senior Member fotiman is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

You would not want to use JavaScript for this. If the site uses PHP, you can access the referrer information like this:


Hope that helps.


9:44 am on Jul 27, 2009 (gmt 0)

10+ Year Member

Hi Fotiman

Thanks - but I can't have explained properly.

I can't use php because this is not all happening in the same session - and, even if it is, the reader will likely have started at the home page and read various other pages of the site, so the original referer will be long gone unless we trap it at the next page.

I am assuming that the user might not complete the inquiry form on their first visit to the site. They may well look at competitor services, consider things and then come back a few weeks later. So, the only way to store the 'orginal' referer is through a cookie. Yes, could use PHP to write the cookie as soon as they entered the site, but the regular pages aren't php-driven and so JavaScript seems the obvious way.


1:55 pm on Jul 27, 2009 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member

I'd recommend a search in your favorite search engine for "javascript write cookie" or "javascript set cookie." You'll find plenty of straightforward functions you can use to make cookie handling easier. :)

Featured Threads

Hot Threads This Week

Hot Threads This Month