简体   繁体   English

如何为站点别名设置会话。 PHP Apache2

[英]How to setup session for a site alias. PHP Apache2

I'm running php on an Apache2 server with virtual hosts. 我在具有虚拟主机的Apache2服务器上运行php。 I have 2 domains, let's say domain1.com and domain2.com (NOT subdomains) 我有2个域,例如domain1.com和domain2.com(不是子域)

domain2.com is a ServerAlias of domain1.com domain2.com是domain1.com的ServerAlias

The session on domain1.com is working just fine. domain1.com上的会话运行正常。 However, I can't get session variables to save on domain2.com. 但是,我无法将会话变量保存在domain2.com上。

I don't believe my session is saving, because it's not carrying over between pages. 我不认为自己的会话可以节省资源,因为它不会在页面之间传递。 I set the variables on my index.php page. 我在index.php页面上设置了变量。 I can dump the session and see that it was initially set. 我可以转储该会话,并看到它是最初设置的。 Then my index.php redirects to home.php where I have this at the top of home.php 然后我的index.php重定向到home.php,在home.php的顶部

<?php
session_start();
var_dump($_SESSION); 
?>

I'm getting an empty array on home.php 我在home.php上得到一个空数组

My phpinfo() settings are exactly the same for my session information on the 2 domains. 我的phpinfo()设置与我在2个域上的会话信息完全相同。

I'm stuck, not sure if this is a php issue, or an apache setting. 我被卡住了,不确定这是否是php问题或apache设置。 Any help is greatly appreciated! 任何帮助是极大的赞赏!

Sessions in php are normally maintained in php by cookies. php中的会话通常由cookie维护在php中。 What you are probably seeing is the value of session.cookie_domain being set to your working domain set in the ini. 您可能会看到的是session.cookie_domain的值设置为ini中设置的工作域。 Use ini_set or session_set_cookie_params before your session_start call to rectify. 在session_start调用之前使用ini_set或session_set_cookie_params进行纠正。

Another option that worked for me: is to force the name of the session: 对我有用的另一个选项:强制会话的名称:

session_name("myWebsite");
session_start(); 

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

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