0

i Have setup 2 domains/sites in the ISPConfig on amazon Web server EC2 instance,

i have a domain named app.example.com and the other is https://www.example.com Both domains setup in ISpConfig3. so both have separate webroot and code files. I have setup some session variables on app.example.com , while on https://www.example.com i have only static contents. But in some cases i need to access the session variables from app.example.com to my top domain https://www.example.com

I have tried setting on http://app.example.com

ini_set('session.cookie_domain', '.example.com' );

session_start();

$_SESSION['user_name']= "my_session";

and then accessing $_SESSION['user_name'] on https://www.example.com

print_r($_SESSION['user_name']);

But nothing seems to be working, How can i make this to be working?.

Asghar
  • 2,336
  • 8
  • 46
  • 79
  • 1
    I think this post can answer your question: [http://stackoverflow.com/questions/7328225/sharing-php-session-session-across-multiple-domain][1] [1]: http://stackoverflow.com/questions/7328225/sharing-php-session-session-across-multiple-domain – Alan Gularte Dec 07 '12 at 11:55

2 Answers2

1

The first comment of @Alan Gularte replies quite well I think. If it does not work, you may consider writing a cookie yourself to pass info back and forth.

setcookie ("PassMySessionName", $_SESSION['user_name'], time() - 3600, "/", "example.com");

Setting cookie domain to "example.com" will make it available both on www. and app.

On the other side you will find it in the $_COOKIE array.

$PassedUserName=$_COOKIE["PassMySessionName"];

If you need it all to work without cookies enabled, it gets much more complicated, as $_SESSION will work appending parameters to your urls transparently. In that case (if you link from one site to the other) you may add them manually to the urls.

FrancescoMM
  • 2,845
  • 1
  • 18
  • 29
0

I would like to make a little correction,

Bad: setcookie ("PassMySessionName", $_SESSION['user_name'], time() - 3600, "/", "example.com");

Correct: setcookie ("PassMySessionName", $_SESSION['user_name'], time() + 3600, "/", "example.com");

  • 1
    This should be a comment on the answer you're correcting. As an answer, we don't see what you're referring to. (And don't worry, being too old is not a problem). If possible, try to elaborate on why you're correction is better. – Dettorer Dec 16 '14 at 12:07
  • Ok, thanks for the advice, I'm new here; I will redo it ASAP, now I can't because i have less than 50 reputation to comment. – Karim Kaci Dec 16 '14 at 12:40