简体   繁体   English

跨多个域(非子域)的PHP会话

[英]PHP Sessions across multiple domains (not subdomains)

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. 我正在尝试进行设置,因此,如果您登录到我的网站(使用codeigniter),则该会话将转移到我的多个网站的其他域(而非子域)中。 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. 例如,如果您转到domain.com并登录,然后转到domain2.com,则您已经登录到domain2.com。

I cannot figure out where to start. 我不知道从哪里开始。

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. 不能使用cookie,因为它们已绑定到域。

You need to use one domain as the main login system (keyDomain). 您需要使用一个域作为主登录系统(keyDomain)。 Then for each other domain2, you query the keyDomain for a temporary key, use this key to log to the domain2. 然后,对于每个其他domain2,您在keyDomain中查询一个临时密钥,使用此密钥登录到domain2。 The server of domain2 will check the key on keyDomain. domain2的服务器将检查keyDomain上的密钥。

You need two methods on keyDomain. 您需要在keyDomain上使用两种方法。 - One to build the keys. -一个来构建密钥。 They must be time dependent and valid for 5min. 它们必须与时间有关,并且有效期为5分钟。 - 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). (当前密钥和前一个密钥均有效,因此有效期为10分钟)。

The key is simply a string containing time+user_ID+salt, all encoded. 密钥只是一个包含time + user_ID + salt的字符串,均已编码。

You should look at how facebook connect work. 您应该看一下Facebook连接的工作方式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM