w3coded php setcookie w3coded php setcookie Meta Stack Overflow w3coded php setcookie , w3coded php setcookie Stack Overflow for Teams w3coded php setcookie Where developers & w3coded php setcookie technologists share private knowledge with w3coded php setcookie coworkers w3coded php setcookie , w3coded php setcookie GitLab launches Collective on w3coded php setcookie Stack Overflow , w3coded php setcookie Stack w3coded php setcookie Overflow Public w3coded php setcookie questions & answers w3coded php setcookie
So your cookie is not giving the relevant information to the browser for it to be accessible across subdomains and/or the directory path.
document.cookie = 'ppkcookie1=testcookie; expires=Thu, 2 Aug 2001 20:47:11 UTC; path=/; ;domain=.example.com'
Note, .example.com
is just an example domain (you need yours in there), and you do not need a wildcard other than the initial .
for it go across all subdomains. And you need to generate an expires=
date. From QuirksMode:
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
} else {
var expires = "";
}
document.cookie = name+"="+value+expires+"; path=/; domain=.example.com";
}
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/; domain=.example.com";
}
createCookie('cookieee','stuff','22');
http://example.com/test/test.php
<pre>
<?php
print_r($_COOKIE);
?>
Can you give some more information? Are they both on the same domain just different files? Is the line
document.cookie = cookieName+"="+cookieValue;
If you want to expand the domain available to the cookie you need to specify it as part of the cookie:
document.cookie = cookieName + '=' + cookieValue + '; path=/;';
For setting the cookie:
document.cookie = "key=value; expires=Fri, 03 Aug 2018 12:00:00 UTC; path=/";
For setting the cookie:
setcookie('key', 'value', (time() + (3600*2)), '/');
For accessing:
if (isset($_COOKIE['key'])) echo $_COOKIE['key'];
Last Update : 2023-09-22 UTC 13:52:11 PM
Last Update : 2023-09-22 UTC 13:51:32 PM
Last Update : 2023-09-22 UTC 13:51:26 PM
Last Update : 2023-09-22 UTC 13:51:12 PM
Last Update : 2023-09-22 UTC 13:51:05 PM
Last Update : 2023-09-22 UTC 13:50:52 PM