I'm trying to set a cookie with javascript and read it in an other page with php. I am able to write the cookie by doing
document.cookie = cookieName+"="+cookieValue;
and i partially works. - The cookie is written, and I am able to read it with $_COOKIE[cookieName]
but ONLY in the same web page.
Which is not quite usefull really. I need to read it in another page. I usually develop in asp.net and c#, so I'm preety new to php. Am I doing something wrong?
Thank you for your time!
EDIT1: both pages are in the same domain.. eg. site.com/index.php -> site.com/index2.php
EDIT2: the cookie is set in one page through:
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();
}
and in another page it can not be accessed, but in that same page it can...
EDIT3:
i tried setting the domain and added path=<?php echo $_SERVER['HTTP_HOST']; ?>
to the javascript code... still nothing..
EDIT4: so far I have..
document.cookie = cookieName+"="+escape(cookieValue)+"; expires="+expire.toGMTString()+"; path=/"+"; domain=.<?php echo $_SERVER['HTTP_HOST']; ?>";
and still i can read the cookie ONLY from the same page..
EDIT5: oh.. my .. god... it was a typo all along... just needed to remove the" path=/"+"; dom..." i am so ashamed of myself right about now... in the meantime i also reset my cookies, so Jared now i unfortuneatly can't accept your post as anwser... i brought shame upon my name!!!....