A very strange problem occurred when verifying the login cookie in php. maybe everyone did not pay attention to it. Thank you !!! Hello everyone, I am not talking about the code directly on a php website recently: I have successfully added a cookie upon login: setcookie (& quot; user & quot;, $ Email, time () + 24*60*60); header (& quot; location: website. A strange problem occurred when co php verified the login cookie. maybe everyone did not pay attention to it. Thank you !!!
Hello everyone, I am currently working on a php website. I don't talk much about the direct code:
Cookie added successfully upon login:
Setcookie ("user", $ Email, time () + 24*60*60 );
Header ("location: http://website.com/MyProfile.php ");
Go to the page to verify the cookie:
If (isset ($ _ COOKIE ["user"])
// Echo $ _ COOKIE ['user'];
{
Click exit to delete the cookie:
Setcookie ("user", "", time ()-24*60*60 );
("Location: http://website.com/index.php ");
The problem is as follows:
You can log on normally for the first login, and then click exit (clear cookie ). Then, log on to the MyProfile page. the cookie is not found (make sure the password is correct ). The second login will be normal. I have tested it, and it is okay to set and delete it. why didn't I notice it? Maybe it's a problem with the header function?
Answer
------ Solution --------------------
The header does not conflict with the setcookie.
No other output is allowed before these two operations.
We recommend that you check the code.
------ Solution --------------------
We recommend that you change to another browser and update the cache before testing.
------ Solution --------------------
This is the case,
The cookie takes effect only on the new page.
------ Solution --------------------
It takes effect only after the second login.
------ Solution --------------------
After the first login, I wrote an error upstairs.
------ Solution --------------------
Have you tested other browsers?