I have a cookie that I set the value in PHP, and I would like to the its value in javascript. I cant find any tutorials on this, I find tutorials that set and get values from either php or javascript, but i cant find a tutorial of setting a cookie in php and getting its value in JavaScript. The php cookie is workign i have echoed it.
PHP
setcookie($name, $pID, time() + (86400 * 30), "/");
Javascript
I tried this from W3 school but it doesnt work.
function displayA() {
var name = "id=";
var decodedCookie = decodeURIComponent(document.cookie);
var ca = decodedCookie.split(';');
for(var i = 0; i <ca.length; i++) {
var c = ca[i];
while (c.charAt(0) == ' ') {
c = c.substring(1);
}
if (c.indexOf(name) == 0) {
return c.substring(name.length, c.length);
}
}
alert(c);
}