PHP Sessions across multiple domains (not subdomai

2019-08-07 10:08发布

问题:

I'm trying to set it up so if you log in to my website (using codeigniter) the session carries over to other domains (not subdomains) of my multiple websites. For example, if you go to domain.com and log in, then go to domain2.com, you'll already be logged in at domain2.com.

I cannot figure out where to start.

回答1:

First approach that comes to mind would be using a shared database that would hold the 'logged in' flag, that each domain would poll and update. Using cookies is not an option as they are bound to the domain.



回答2:

You need to use one domain as the main login system (keyDomain). Then for each other domain2, you query the keyDomain for a temporary key, use this key to log to the domain2. The server of domain2 will check the key on keyDomain.

You need two methods on keyDomain. - One to build the keys. They must be time dependent and valid for 5min. - One to check the key, check the given key against the current one, and then agains the previous one in case the time slot have changed between query and check. (Both current key and previous one are valid so it make a 10min validity).

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

You should look at how facebook connect work.