Home > Article > Web Front-end > Regarding the use of COOKIE under the first-level domain name under the second-level domain name_javascript skills
If we want to use a cookie under www.jb51.net, 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, we must also set it in the second-level domain name. What should I do if it is used under a high-level domain name?
For example, if our first-level domain name is a website such as: www.jb51.net, and below it there is a second-level domain name such as: bbs.jb51.net
We want to achieve a After logging in to the first-level domain name, keep this cookie to the second-level domain name, that is, to achieve the effect of synchronous login.
So how do we set this cookie? It is actually very simple.
Take the domain name (www.jb51.net) just now, we can set cookies like this: setcookie("fangbinbin","mengfei",time() 3600,"/","jb51.net ");
Then we can directly use (echo $_COOKIE['fangbinbin'];) under www.jb51.net and bbs.jb51.net to output the value of the set cookie
This solves the problem of synchronous login! !