PHP Multi-Domain Sessions; ini_set Not Working?
Posted
by
SumWon
on Stack Overflow
See other posts from Stack Overflow
or by SumWon
Published on 2011-01-08T01:29:11Z
Indexed on
2011/01/08
2:53 UTC
Read the original article
Hit count: 177
Hello,
I'm trying to set it up so if you log in to my website the session carries over to all sub-domains of my website. For example, if you go to domain.com and log in, then go to sub.domain.com, you'll already be logged in at sub.domain.com.
To my understanding, you would want to use ini_set('session.cookie_domain','.domain.com') and then session_start(), then set your session variables, but this isn't working.
Example of what I'm doing:
Code for domain.com:
<?php
ini_set('session.cookie_domain','.domain.com');
session_start();
$_SESSION['variable'] = 1;
?>
Code for sub.domain.com:
<?php
session_start();
echo $_SESSION['variable'];
?>
But $_SESSION['variable'] isn't set.
I've also tried using ini_set() in the sub.domain.com code, but it made no difference. I've verified that setting session.cookie_domain is working by using ini_get().
What am I doing wrong? Thanks!
© Stack Overflow or respective owner