I have set my cookie in PHP using the following:
setcookie("id", 100, time()+100000, "/AP", "www.mydomain.com", 0, true);
When I look at the cookies stored in the browser it looks like this:
Name: id
Content: 100
Domain: .www.mydomain.com
Path: /AP
Notice the . in the Domain
When I set a cookie in javascript I get the same results except:
Name: id
Content: 100
Domain: www.mydomain.com
Path: /AP
The domain is different. Why does my PHP cookie put a '.' in front of www.mydomain.com and javascript does not.
The following is the javascript code that I'm using to create a cookie:
function SetCookie(cookieName,cookieValue,nDays) {
var today = new Date();
var expire = new Date();
if (nDays==null || nDays==0) nDays=1;
expire.setTime(today.getTime() + 3600000*24*nDays);
document.cookie = cookieName+"="+escape(cookieValue)
+ ";expires="+expire.toGMTString();
}
Any ideas?
Update:
When I try to read this using the following function in javascript:
function ReadCookie(cookieName) {
var theCookie=""+document.cookie;
var ind=theCookie.indexOf(cookieName);
if (ind==-1 || cookieName=="") return "";
var ind1=theCookie.indexOf(';',ind);
if (ind1==-1) ind1=theCookie.length;
return unescape(theCookie.substring(ind+cookieName.length+1,ind1));
}
I can't get the value using the ReadCookie function (above) from the cookie that contains:
Domain: .www.mydomain.com
However the cookie that contains:
Domain: www.mydomain.com
works just fine.