Accessing $_COOKIE immediately after setcookie()

前端 未结 9 914
轻奢々
轻奢々 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 06:04

    Your script's setcookie() function runs when the web browser requests the page for the first time, in your case the reload. This cookie is stored in the users browser and isn't available to your script running on the server until the next request, or in your case the next reload.

    Upon the next request the browser sends that cookie to the server and the array $_COOKIE will have the value that you initially set and the browser sent back upon the second request.

提交回复
热议问题