Share a SESSION under multiple domain names

Source: Internet
Author: User
To implement multi-domain sharing sessions, you must first understand the operation mechanism of sessions. I will not talk about the basic concepts. Session runs like this: User A accesses Site Y. If Site Y executes session_start ();(... to implement multi-domain sharing sessions, you must first understand the operation mechanism of sessions. I will not talk about the basic concepts.
The session runs like this:
User A accesses Site Y. If Site Y executes session_start (); (the following assumes that session_start () always exists), A session_id is generated, this session id is generally saved to user A in the form of a cookie. set session in ini. use_only_cookies are set to 1, and the session id must be transmitted as a COOKIE .). At this time, the session id is represented as $ _ COOKIE ['phpsessid ']; (PHPSESSID can be modified using the session_name () function)
User A then accesses the session id ($ _ COOKIE ['phpsessid ']), which is sent to Site Y every time A accesses Y.
On Site Y, there is such a directory to save the actual data of the SESSION. Site Y receives the session id, obtains the association with the session data through the SESSION id, and returns the SESSION data.

You may have come up with the idea that sessions between the server and the client are linked by a session id, and SESSION data is saved in a specific folder in the form of common files.
To implement different domain names, we only need to meet the following two conditions:

1) the SESSION data directories of different domain names are unified or updated synchronously.

2) use a unified session id for the same customer

The implementation of the first condition.
If it is the same server, no configuration is required.
If it is cluster/distributed, I don't want to talk about it .. I have more experience in directory sharing than I can do for distributed applications. I have not conducted many server tests, and there are all subjective and objective reasons.

Here I mainly want to talk about the second condition -- to make different domain names have a unified SESSION ID.
So how should we unify it?
First, the session id must be passed between different domain names, and because the cookie must be for the domain name, the transfer action is completed by the client. If the transfer process is not completed by the client, the domain name that receives the transfer does not know the target customer.

The second step is to modify the session id under the domain name accepted for transfer.

How to pass:
In HTML, we can use many methods. For example
Iframe

Or. js

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.