jonnyfolk
asked on
find HTTP_REFERER to set cookie
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=goo gle
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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,d omain,secu re) {
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
if (document.referrer&&docume nt.referre r!="")
{
Ê 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
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,d
document.cookie = name + "=" + escape (value) +
((expires) ? "; expires=" + expires.toGMTString() : "") +
((path) ? "; path=" + path : "") +
((domain) ? "; domain=" + domain : "") +
((secure) ? "; secure" : "");
}
if (document.referrer&&docume
{
Ê 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
ASKER
It's ok, venkateshwarr, I saw that my cut and paste was corrupted. All is well and I am grateful for the help.
ASKER
Hi venkateshwarr,
I just tried the tagged solution:
SetCookie ("pagereferrer", "http;//mysite.com?srce="+ document.r eferrer, 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
I just tried the tagged solution:
SetCookie ("pagereferrer", "http;//mysite.com?srce="+
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
I did not test it... try this,
var refrer = document.referrer+"";
var rhost= refrer.split(".");
rhost= rhost[0].split("/");
document.write(rhost[2]);
var refrer = document.referrer+"";
var rhost= refrer.split(".");
rhost= rhost[0].split("/");
document.write(rhost[2]);
SetCookie ("pagereferrer", "http;//mysite.com?srce="+