PHP two domain name using cookies under the first-level domain for cross-domain logins
We usually use cookies only when used in this site, that is, only under a domain name.
If we want to use a cookie under www.xhbin.com, just set a cookie in the file below the station.
But what if we want to implement the cookie set under the first-level domain name and use it under Level two domain name?
For example: We are in the first-level domain is a site such as: www.xhbin.com, he has a two-level domain name, such as: bbs.xhbin.com
We want to achieve on the first-level domain name login, keep this cookie to level two domain name, that is, to achieve the effect of synchronous login,
So how do we set this cookie?? It's actually very simple.
Take just that domain name (www.xhbin.com), we can set cookies:setcookie ("Fangbinbin", "Mengfei", Time () +3600, "/", ". Xhbin.com" );
So we can www.xhbin.com here? and bbs.xhbin.com under direct use (echo $_cookie[' Fangbinbin '); will be able to output the value of that set cookie.
This way to solve the problem of the synchronization login!!
?
Of course, if it involves 3 or more domain names, it is best to have a unified login interface and exit interface, such as log in unified post to the first-level domain login page.
?
The user login session information related to this cookie is then saved to the Key-value type of cache, such as memcached, MEMCACHEDDB and so on, try to avoid writing files or db to reduce IO, provide user experience.