在另一个网站上使用相同的php会话链接点击 [英] use same php session on another website on link click

查看:153
本文介绍了在另一个网站上使用相同的php会话链接点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个问题。假设我在网站 domain1.com 上,点击 domain1.com 上的链接,转到 domain2.com 。但我想使用 domain1.com中的 session_start()设置的相同 session_id() domain2.com 上。如何在PHP中完成此操作?

I have a question. Let's say I am on website domain1.com and I click on a link on domain1.com that brings me to domain2.com. But I want to use the same session_id() that was set with session_start() in domain1.com on domain2.com. How do I accomplish this in PHP?

谢谢。

推荐答案

>由于 session_id()本身不包含任何数据,因此需要考虑几件事情:

As the session_id() itself doen't contain any data, there are a couple of things to consider:


  • 如果会话是在Cookie中设置的,则无法转移(除非到子域),请务必通过GET转移

  • 要使与SESSION相关的数据跨服务器同步,您必须共享文件系统(例如通过 GlusterFS ) ),至少保存SESSIONS的路径(例如/ tmp / php)

  • 如果您在SESSION中保存对象,请确保它们在两个服务器上都可用

  • If the session is set in a cookie, you can't transfer it (unless to a subdomain), make sure you transfer it via GET
  • In order to have the data associated with the SESSION sync accross the servers, you have to share the file system (e.g. via GlusterFS), at least for the path the SESSIONS are saved (e.g. /tmp/php)
  • if you save objects in the SESSION make sure they are available on both servers

如果两个域都指向同一服务器上的同一个文档根目录,则只需要关心第一点

If both domains are pointing to the same document root on the same server you only need to take care about the first point

如果你只想使用 session_id()而不是关联的数据,你可以设置id: session_id 'yourSessionIdFromDomain1')

If you only want to use the session_id() and not the associated data, you can just set the id: session_id('yourSessionIdFromDomain1')

这篇关于在另一个网站上使用相同的php会话链接点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆