The code is as follows:
header("Content-type: text/html; charset=utf-8"); if (isset($_COOKIE['test'])) bracket Cookies obtained by echo' are:'. $_COOKIE['test']; bracket Elseif (setcookie ('test',' okh', time () plus 3600, '/', '.us.com')) bracket Echo' set cookies：test'; bracket Else bracket Echo' nothing'; bracket
Using us.com to access, the above code has been successfully set under chrome, but it has not been recorded.
Looking for the reason for half a day, a friend told me from the manual:
The domain that the cookie is available to. 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:
- Visit with www.us.com
The code before modification was
Setcookie(‘test’, ‘okh’, time () plus 3600, ‘/’, ‘www.us.com’)
This is the normal setting and normal recording.
But there are two problems:
- How do I set cookies for domain names without WWW? For example: us.com
- Although www.us.com can be used under www.us.com, it cannot be used under us.com. How to set cookies to make them universal?
PS: I know that the parameter domian can be successfully set, but my requirement is to set cookies under different domains, not just under one domain name, so I still hope to keep this parameter, and it is better to set such parameters as:.us.com
This domain name is special. Firefox does not think
us.comSecond-level domain of:
var eTLDService = Components.classes["@mozilla.org/network/effective-tld-service; 1"] .getService(Components.interfaces.nsIEffectiveTLDService); eTLDService.getBaseDomain(gBrowser.selectedTab.linkedBrowser.currentURI); /* www.us.com */
us.comIneffective_tld_names.datThe document lists:
// CentralNic : http://www.centralnic.com/names/domains // Requested by registry <email@example.com > 2012-09-27 ae.org ar.com br.com cn.com com.de de.com eu.com gb.com gb.net gr.com hu.com hu.net jp.net jpn.com kr.com no.com qc.com ru.com sa.com se.com se.net uk.com uk.net us.com us.org uy.com za.com