PHP second-level domain names use cookies under the first-level domain name to achieve cross-origin login. we generally use cookies only in this site, that is, only for one domain name. If we want to use a cookie under www.xhbin.com, we only need to use the COOKIE under the PHP second-level domain name under this site to implement cross-origin login.
We generally use cookies only on this site, that is, only for one domain name.
For example, if we want to use a cookie under www.xhbin.com, we only need to set a cookie in the file below this site.
But if we want to implement the cookie set under the first-level domain name and use it under the second-level domain name, what should we do ??
For example, a first-level domain name is a website such as www.xhbin.com, which has a second-level domain such as bbs.xhbin.com.
We want to keep the cookie to the second-level domain name after logging on to the first-level domain name, that is, to achieve synchronous login,
So how do we set this cookie ?? It is actually very simple.
Take the domain name www.xhbin.com for example, we can set the cookie as follows:Setcookie ("fangbinbin", "mengfei", time () + 3600, "/", ".xhbin.com ");
So we can go to www.xhbin.com? And bbs.xhbin.com directly (echo $_ COOKIE ['hangbinbinbin'];) To output the set cookie value.
This solves the problem of synchronous login !!
?
Of course, if three or more domain names are involved, it is best to have a unified logon interface and exit interface, such as a unified POST to the login page of the first-level domain name during logon.
?
Then, save the user login Session information related to this Cookie to the Key-Value type cache, such as memcached and memcachedDB, to avoid file writing or database IO reduction, provides a user experience.