Accessing $_COOKIE immediately after setcookie()

前端 未结 9 921
轻奢々
轻奢々 2020-11-22 05:43

I\'m trying to access a cookie\'s value (using $_COOKIE) immediately after calling the setcookie() function in PHP. When I do so, $_COOKIE[\

9条回答
  •  悲哀的现实
    2020-11-22 05:58

    You have to set the cookie variable by yourself if you need it immediately, by the time you load another page the real cookie would have been set as a result of the setcookie method.

    setcookie('name', $value, time()+60*30);
    $_COOKIE ['name'] = $value;
    

提交回复
热议问题