开发者

Problem with setcookie in PHP

开发者 https://www.devze.com 2023-03-20 08:03 出处:网络
if( isset($_COOKIE[\"cl1\"] ) ) { echo $_COOKIE[\"cl1\"]; } else { setcookie(\"cl1\",\"me\",time()+ 3600); }
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

精彩评论

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