I have successfully set a cookie cad
and can see it in firefox cookie-search.
if(isset($_COOKIE[\'cad\'])){
echo\'YES\';
}else{
echo\'NO\';
}
//par
When you set a cookie, you can set various options. Cookies, as everyone knows, can only be accessed by scripts on the same domain, but you can also affect what path the cookie is set on. For instance, a cookie set on /foo/bar.php
may not be accessible on /foobar.php
.
PHP by default sets the cookie to the current path. So, with the above example, the cookie is set to the path /foo/
, and is not accessible outside that path.
When you set your cookies, therefore, it's best to be explicit about where you want them to be available. In PHP this is very easy; just set an extra parameter specifying the path. As you indicate in the comments, you need the most liberal path possible /
, which means "anywhere on this domain".
setcookie('cad', 'somevalue', 0, '/');
See the setcookie documentation in the PHP manual.