php cookie does not work at the first time reading

前端 未结 3 1132
有刺的猬
有刺的猬 2020-12-12 06:18

I am a beginner for PHP and studying to use cookie for login. Would any body please check my code to see what is my problem, or let me how to fix this problem.

Wh

3条回答
  •  星月不相逢
    2020-12-12 07:12

    setcookie only sets up the header, that is being sent to the client. It doesn't change the $_COOKIE superglobal.

    In other hand - $_COOKIE is filled up with the cookies sent from the client

    So at first step - you set the cookie with setcookie and have nothing in $_COOKIE because client hasn't sent it yet, and will only on the next request.

    And there is no way of doing what you want, rather than modifying $_COOKIE manually

    PS: it is a bad idea to put user's password in the cookie

提交回复
热议问题