简体   繁体   中英

How to setup session for a site alias. PHP Apache2

I'm running php on an Apache2 server with virtual hosts. I have 2 domains, let's say domain1.com and domain2.com (NOT subdomains)

domain2.com is a ServerAlias of domain1.com

The session on domain1.com is working just fine. However, I can't get session variables to save on 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. 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

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

I'm getting an empty array on home.php

My phpinfo() settings are exactly the same for my session information on the 2 domains.

I'm stuck, not sure if this is a php issue, or an apache setting. Any help is greatly appreciated!

Sessions in php are normally maintained in php by cookies. What you are probably seeing is the value of session.cookie_domain being set to your working domain set in the ini. Use ini_set or session_set_cookie_params before your session_start call to rectify.

Another option that worked for me: is to force the name of the session:

session_name("myWebsite");
session_start(); 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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