Cookies aren't persisting in PHP?

后端 未结 4 702
Happy的楠姐
Happy的楠姐 2021-01-27 03:24

How do I get the cookies to persist in php?


give_cookie.php



        
4条回答
  •  既然无缘
    2021-01-27 04:18

    Other answers are right, but there is another consideration. Cookies get set when the server sends the html to the client, and they are received from the user when the user requests the page. That means, if you try to read a cookie you just set correctly, it will be empty until next time the user reloads the page. The only way to avoid this is, as you did, not sure if on purpose or not, to assign manually the cookie's value and set it at the same time since it is a superglobal. This is NOT a good practice since the value of the Cookie gets lost for this execution. This should work but not do much work:

    give_cookie.php

    
    

    jar.php

    
    

    PS, there are many more problems with your code (besides it does nothing useful). Tell us what you are trying to achieve so we can help you a bit more.

提交回复
热议问题