Home  >  Article  >  PHP Framework  >  Cookie settings are invalid in yii2

Cookie settings are invalid in yii2

王林
王林Original
2019-12-18 16:46:002701browse

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.

Cookie settings are invalid in yii2

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?

Cookie settings are invalid in yii2

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.

Cookie settings are invalid in yii2

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn