Home > Article > PHP Framework > Cookie settings are invalid in yii2
When I was learning about the cookie settings of the yii2 framework, I encountered a very tangled problem. That is, when we set cookies, they are always invalid. No matter how you set it up, it is wrong. Copying the code from the manual is still ineffective. How is this going? After some research, I found a solution.
Please look at my code: The premise is that I have configured the cookie key by default.
At first glance, there seems to be nothing wrong with it, right? But there is a problem with writing this way. Friends who don’t believe it can try it themselves. So what is the correct solution?
This is because in the process of learning and debugging, I artificially added die, exit and other statements, so the set cookies were not sent to the client, causing The value obtained every time is incorrect.
How to configure the cookie key, file address\frontend\config\main.php
Why you need to configure the cookie key, the official website has made it very clear . If not set, it will be invalid when checking whether the cookies are correct.
Recommended related articles and tutorials: yii tutorial
The above is the detailed content of Cookie settings are invalid in yii2. For more information, please follow other related articles on the PHP Chinese website!