Accessing $_COOKIE immediately after setcookie()

前端 未结 9 905
轻奢々
轻奢々 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:54

    The cookie isn't set until the response is sent back to the client, and isn't available in your PHP until the next request from the client after that.

    However, when you set the cookie in your script, you can do:

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

提交回复
热议问题