PHP two domain names use cookies on the first-level domain to enable cross-domain logins

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

  • 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.