0

login.php

session_start();
$_SESSION['aid'] = 1;
echo $_SESSION['aid']; // 1

then index.php

session_start();
echo $_SESSION['aid']; // nothing is echoed  
$_SESSION['test'] = 323;
echo $_SESSION['test']; // 323

error_log

PHP Notice: Undefined index: aid in...

this happens only on my subdomain - admin.example.com
on main domain - example.com - everything is ok
also this happens only on remote server
on my localhost - xampp, win7, chrome - it's ok

any help?

qadenza
  • 9,025
  • 18
  • 73
  • 126

1 Answers1

1

You should set the cookie domain to ".example.com" before you start your session (on all scripts on all subdomains, else the cookie is not even valid on a different (sub)domain.

session.cookie_domain = ".example.com"

Or make use of session_set_cookie_params():

session_set_cookie_params(0, '/', '.example.com');
session_start(); 

See also this question: Allow php sessions to carry over to subdomains

Piemol
  • 857
  • 8
  • 17