php,外部域的ajax认证
假设我有domain-a.com(A)和domain-b.com(B),
我希望能够在两个域之间共享php会话,统一登录,一旦用户登录到A,就会自动登录登录到 B,反之亦然。
现在,我面临的问题是,即使我设法让浏览器通过 Access-Control-Allow-Origin 标头通过 ajax 与外部域对话,它也不会设置 cookie(请不要告诉我“你无法为另一个域设置/获取 cookie,这不是问题”)
流程如下:
A 会向 B 发送凭据
如果凭据正常,
-B 使用 SESSID 进行应答,以保持一致与用户凭据(这样就可以两种方式生成,即:从 A 登录或从 B 登录),稍后将使用它来共享 B 上创建的会话
- 同时我希望 B 可以为其域写入 cookie,但到目前为止我还没有桌子。
我在这里需要的非常简单,一旦 A 的凭据正确,我希望服务器 B 可以为其域(B)写入他的 cookie,我可以从标头中看到,从技术上讲,它正在设置 cookie,但浏览器不是并没有真正在听。有什么想法吗?我是否处于浏览器不兼容的危险区域?从技术上讲,所有这些对于最新的浏览器来说应该是相当普通的。
谢谢!
Suppose I have domain-a.com (A) and domain-b.com (B)
I'd like to be able to share php sessions between the two domains unifying logins in a way that once the user is logged to A is automatically logged into B and vice versa.
Now, the problem I'm facing is that even if I managed to have the browser talk via ajax to an external domain via the Access-Control-Allow-Origin header it won't set cookies (please don't tell me "you can't set/get cookies for another domain, this is not the problem")
here's the flow:
A sends credentials to B
if credentials are OK
-B answers with the SESSID made in order to be consistent with the user credentials (so that it can be generated both ways ie: login from A or login from B), this will be used later to share the session created on B
-At the same time I'd like that B could write cookies for its domain, but so far I wasn't able.
What I need here is very simple, once that the credentials from A are correct i'd like that server B could write his cookie for his domain (B), I can see from the headers that technically it's setting cookies, but the browser isn't really listening. any idea? am I playing in a dangerous zone of incompatibilities between browsers? technically all of this should be pretty vanilla for the recent browsers.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果domain-a.com和domain-b.com在同一台服务器上,您可以实现自己的会话或尝试使用
session_id
设置会话 ID。如果它们位于不同的服务器上,您将需要使用某种复制或创建 API 来授权第三方域上的用户。If domain-a.com and domain-b.com are on the same server, you can implement your own sessions or try to use
session_id
to set session ID. If they are on different servers, you`ll need to use some sort of replication or create an API to authorize users on third-party domains.