PHP - funny behaviour of cookie variables and session variables

后端 未结 3 1266
-上瘾入骨i
-上瘾入骨i 2021-01-26 17:10

I wrote a little PHP script below to demonstrate my question. Run the code below like this: http://localhost/test.php?test=10, then run http://localhost/test.php?test=11, then

3条回答
  •  生来不讨喜
    2021-01-26 17:25

    Maybe because I cant a cookie and immediately read the same cookie?

    Exactly. The cookie you sent is available in $_COOKIE array only in the next request, because the $_COOKIE superglobal array is filled with the data, that comes in the client's request. And at first request it is nothing.

提交回复
热议问题