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*6 a strange problem occurred when verifying the login cookie in php. 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 );
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?
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.