For cookie read/write operations, if the domain name is not configured properly, only one domain name may be used, such as www.111cn.net and 111cn.net. The latter includes the former. The following is an example. For cookie read/write operations, if the domain name is not configured properly, only one domain name may be used, such as www.111cn.net and 111cn.net. The latter includes the former. The following is an example.
Script ec (2); script
During local debugging today, a cookie cannot be written into the system. The environment is as follows:
Domain Name: 111cn.net
Browser: chrome34
Code:
| The Code is as follows: |
|
Header ("Content-type: text/html; charset = UTF-8 ");
If (isset ($ _ COOKIE ['test'])
{
Echo 'the cookies obtained are: '. $ _ COOKIE ['test'];
}
Elseif (setcookie ('test', 'okh', time () + 3600, '/', '.111cn.net '))
{
Echo 'set cookies: test ';
}
Else
{
Echo 'nothing ';
}
|
Access with 111cn.net. The above code has been successfully set in chrome, but it has never been recorded. After looking for reasons for half a day, a friend told me from the manual:
The domain that the cookie is available. setting the domain to 'www .example.com 'will make the cookie available in the www subdomain and higher subdomains. cookies available to a lower domain, such as 'example. com 'will be available to higher subdomains, such as 'www .example.com '. older browsers still implementing the deprecated» RFC 2109 may require a leading. to match all subdomains.
So I made such an adjustment:
Access with www.111cn.net
The code before modification is
1
Setcookie ('test', 'okh', time () + 3600, '/', 'www .111cn.net ')
Now the settings are normal, and the records are also normal.
However, there are two problems:
How do I set cookies without WWW domain names? For example: 111cn.net
Although www.111cn.net can be used in www.111cn.net, it cannot be used in 111cn.net. How can I set cookies to make them generic?
The reason is as follows:
This domain name is special. Firefox and chrome do not consider www.111cn.net as the second-level domain name of 111cn.net:
| The Code is as follows: |
|
Var eTLDService = Components. classes ["@ maid"]
. GetService (Components. interfaces. nsistmtivetldservice );
ETLDService. getBaseDomain (gBrowser. selectedTab. Reset browser. currentURI );
/*
Www.111cn.net
*/
|
111cn.net is listed in the effective_tld_names.dat file:
A.org
B .cn
It turned out to be such a small problem that plagued me for a day. It was originally for convenience, so I used this domain name as my local development. As a result, I had to change 111cn.net to 1a.com.