homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

Tracking original referrer
track first referer to website

10+ Year Member

Msg#: 3959752 posted 12:01 pm on Jul 26, 2009 (gmt 0)


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.



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

Msg#: 3959752 posted 12:31 am on Jul 27, 2009 (gmt 0)

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.


10+ Year Member

Msg#: 3959752 posted 9:44 am on Jul 27, 2009 (gmt 0)

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.


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

Msg#: 3959752 posted 1:55 pm on Jul 27, 2009 (gmt 0)

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. :)

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved