PHP second-level domain names use cookies on the first-level domain names for cross-origin login

Source: Internet
Author: User
Tags set cookie
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.