Solved

find HTTP_REFERER to set cookie

Posted on 2004-04-02
6
369 Views
Last Modified: 2008-03-06
I'd like to know how to set a cookie on my home page according to the search engine which sends the contact.  so if the source is google the cookie id would reflect that source as it would yahoo etc.  If it is easier I could also get the info from tagging the requested url:  http;//mysite.com?srce=google
0
Comment
Question by:jonnyfolk
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
venkateshwarr earned 250 total points
ID: 10747018
This should help you...

<script language="Javascript">

function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}

if (document.referrer&&document.referrer!="")
{
  document.write('Your referre is - '+document.referrer+'<BR>');
  var expdate = new Date ();
  expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
  SetCookie ("pagereferrer", document.referrer, expdate);
}

</script>

0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10747025
for tagged..

SetCookie ("pagereferrer", "http;//mysite.com?srce="+document.referrer, expdate);
0
 

Author Comment

by:jonnyfolk
ID: 10765304
Hi venkateshwarr,

I appreciate the info.

I wondered if there was anything I had to do to get this up and running.

My web page looks like this, but a cookie is not being set:

<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="Javascript">
function SetCookie (name,value,expires,path,domain,secure) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
if (document.referrer&&document.referrer!="")
{
Ê document.write('Your referre is - '+document.referrer+'<BR>');
Ê var expdate = new Date ();
Ê expdate.setTime (expdate.getTime() + (24 * 60 * 60 * 1000)); // 24 hrs from now
Ê SetCookie ("pagereferrer", document.referrer, expdate);
}
</script>


</head>

<body bgcolor="#FFFFFF">

</body>
</html>

Thanks and regards,
Jon
0
Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

 

Author Comment

by:jonnyfolk
ID: 10766312
It's ok, venkateshwarr, I saw that my cut and paste was corrupted.  All is well and I am grateful for the help.
0
 

Author Comment

by:jonnyfolk
ID: 10768199
Hi venkateshwarr,

I just tried the tagged solution:
SetCookie ("pagereferrer", "http;//mysite.com?srce="+document.referrer, expdate);

This gives the result:
http://mysite.com?srce=http://incomingsite.com

What I need is:
http://incomingsite.com?srce=google

capture the google

Regards,
Jon
0
 
LVL 12

Expert Comment

by:venkateshwarr
ID: 10772975
I did not test it... try this,

var refrer = document.referrer+"";
var rhost= refrer.split(".");
rhost= rhost[0].split("/");

document.write(rhost[2]);
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: DanRollins
This article describes a JavaScript program that creates a maze made of hexagonal cells.  In Part 2 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7850-Hex-Maze-Part-2.html), we'll extend the program by adding a depth-…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question