PHP sessions across multiple domains (not subdomains)

I'm trying to configure it, so if you go to my site (using codeigniter), the session is transferred to other domains (and not subdomains) of my several websites. For example, if you go to the .com domain and log in, and then go to the domain2.com, you will already be logged on to domain2.com.

I can’t figure out where to start.

+1
source share
2 answers

The first approach that comes to mind will be to use a common database, which will contain the "logged in" flag, which will check and update each domain. The use of cookies is not an option, as they are associated with a domain.

+1
source

You need to use one domain as the main login system (keyDomain). Then for each other domain2 you request keyDomain for a temporary key, use this key to enter domain 2. Domain2 server checks the key for keyDomain.

You need two methods for keyDomain. - One to build keys. They must be time dependent and valid for 5 minutes. - One check the key, check this key for the current, and then again the previous one, if the time interval has changed between the request and the check. (Both the current key and the previous one are valid, so it makes it valid in 10 minutes).

The key is just a string containing time + user_ID + salt, all encoded.

You should see how facebook works.

0
source

Source: https://habr.com/ru/post/886664/


All Articles