开发者

Problem with setcookie in PHP

if( isset($_COOKIE["cl1"] ) )
{
    echo $_COOKIE["cl1"];
}
else
{
    setcookie("cl1","me",time()+ 3600);
}

if( isset($_COOKIE["cl1"] ) )
{
    echo "the cookie is set";
}

When I run this page the page must 开发者_如何学编程show "the cookie is set" but the screen is empty. Why?


The cookie will not be available until the next page load. The cookie is sent with the page request. A hack to make it so that cookie value will be in the $_COOKIE array on the same page load would be:

setcookie("cl1","me",time()+ 3600);
$_COOKIE['cl1'] = "me";
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜