问题描述
我正在寻找一种在同一服务器上跨多个域维护PHP会话的方法.我将把我的站点与一个简单机器论坛集成在一起,所以我将需要使用基于MySQL的会话.谢谢!
I am looking for a way to maintain PHP sessions across multiple domains on the same server. I am going to be integrating my sites with a Simple Machines Forum so I will need to use MySQL based sessions. Thanks!
推荐答案
根据修改PHP变量的首选方法(Apache的配置.htaccess),将session.cookie_domain值更改为一致的值.
Depending upon your preferred method of modifying PHP variables (Apache's config, .htaccess), change the session.cookie_domain value to be a consistent value.
我有多个子域,Apache配置文件中的每个VirtualHost部分都包含以下行:
I have multiple sub-domains, and each VirtualHost section in the Apache config file contains the following line:
php_value session.cookie_domain mydomain.com
php_value session.cookie_domain mydomain.com
如果在.htaccess文件中进行更改,语法应相似.
The syntax should be similar if you make the changes in a .htaccess file.
已更新bobert5064的评论:
Updated for bobert5064's comment:
对于多个域(即domain1.com,domain2.org),我认为只需要选择一个通用域名(即domain1.com).我从未尝试过这样做,因此无法验证它是否有效,但是逻辑似乎正确.
For multiple domains (ie domain1.com, domain2.org), I think it is only necessary to choose a common domain name (ie domain1.com). I have never tried this, so I cannot verify that it works, but the logic seems accurate.
在 http://us.php.net/manual/en/function.session-set-cookie-params.php .该文档未提及在其他域上设置cookie的能力.
There is also a method to set the variables direction in PHP described at http://us.php.net/manual/en/function.session-set-cookie-params.php. The documentation makes no reference to the ability or inability to set cookies on a different domain.
这篇关于如何在同一服务器上的多个域中维护PHP会话?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!