Why can't the cookies written in AJAX be displayed?
Source: Internet
Author: User
Why can't the cookies written in AJAX be displayed? In a send. in php, this setcookie (& quot; ip & quot;, $ ips, time () + 3600, '/') is written using ajax ,'/'); why does the cookie written in AJAX fail to be displayed on another page?
In a send. php file, I wrote this setcookie ("ip", $ ips, time () + 3600, '/') using ajax ,'/');
Then print_r ($ _ COOKIE) from another page );
But you cannot see the ip address in the cookie array.
Why?
------ Solution --------------------
Check whether there are other outputs before assigning values to cookies?
------ Solution --------------------
Paste your test code
------ Solution --------------------
Test the php code for printing cookies.
Is it running in different tabs of the same browser?
If not, no result is correct.
The result will not be returned until the window for ajax is closed and refreshed (but it will take less than 1 hour)
------ Solution --------------------
The principle is simple,
1. php can obtain the cookie because the browser sends the cookie to php.
2. the cookie set by php is saved in the memory by the browser.
3. when the browser exits or redirects to another website, the expired cookies are saved to the file.
4. the browser process cannot communicate with each other, and the cookie file is not generated. of course, the cookie is invisible.
I hope I have explained it.
------ Solution --------------------
The session only stores the sessionid in the cookie and the expiration time is 0. when the session is left, it will be gone.
You should think about it yourself.
------ Solution --------------------
As long as other pages jump from this ajax page, the session will exist
The principle is simple,
1. php can obtain the cookie because the browser sends the cookie to php.
2. the cookie set by php is saved in the memory by the browser.
3. when the browser exits or redirects to another website, the expired cookies are saved to the file.
4. the browser process cannot communicate with each other, and the cookie file is not generated. of course, the cookie is invisible.
I hope I have explained it.
------ Solution --------------------
It should not be a problem with require. if it is convenient, paste ipfun. php to see it. You can also use firefox or chrome to check whether the cookie (sessionID) exists in the browser.
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.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service