开发者

php checking cookie to set another cookie

i'm setting a cookie using this code:

setcookie("Blah","user",time()+86400);

i'm then checking that cookie on another page and setting another cookie, then redirecting to another page

    if (isset($_COOKIE["Blah"]))
    {
        setcookie("Demo","user",time()+86400);
    }
$url="cd/bar/home.php"
header ("Location: $URL");

however, when it gets to the redirected page it's acting as if the second cookie isn't set (if it matters the second page is in a diff开发者_如何学Goerent subdirectory, so i'm going from .com/fu/home.php to .com/bar/home.php)

on the redirected page i've got this checking the second cookie

<?php
if (isset($_COOKIE["Demo"]))
{
?>
html
<?php
}
?>

i have no idea why it's not recognizing that the cookie is set. i know for a fact that the check for the first cookie is working as expected.


From the manual page for setcookie:

The default value [of the $path argument] is the current directory that the cookie is being set in.

So the cookie is only being set with the /fu/ path. If you want to set it to the global path, say so explicitly:

setcookie("Demo","user",time()+86400, '/');
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜