hello i am trying to pass a cookie from one page to another, and its just not working for some reason
i set the cookie in php.
Page a:
<?php $cc= 'testcookie';
setcookie("cc", $video, time()+36000);
?>
and i try to read the cookie in JS.
Page b:
function readCookie(name) {
var cookiename = name + '=';
var ca = document.cookie.split(';');
for(var i=0;i < ca.length;i++)
{
var c = ca[i];
while (c.charAt(0)==' ') c = c.substring(1,c.length);
if (c.indexOf(cookiename) == 0) return c.substring(cookiename.length,c.length);
}
return null;
}
and i always get null…
when i try to set the cookie in the same page that i try to read it, it works…
any ideas?
You may try
setcookie("cc", $video, time()+36000, "/", "example.com");to specify the domain and the path."/"mean full domain. And sometimes there may occur some problems with cookies if try to use them on the http://localhost/ .