如何在子域中使用php会话[重复]

This question already has an answer here:

I have one domain and sub domain as bellow,

domain-name.local
sub.domain-name.local

I have a login system in domain-name.local and I need to use same sessions to validate while accessing sub.domain-name.local.

As mention in the question I have tried following things in sub domain without success,


Set php.ini session.cookie_domain as .domain-name.local

Results :

firefox- worked ie- not loading while accessing the session from sub domain chrome - not giving any session details


set from php code as bellow

    ini_set('session.cookie_domain', '.domain-name.local');
    session_start();
    var_dump($_SESSION);

Results :

firefox - not giving any session details , ie- not loading while accessing the session from sub domain, chrome - not giving any session details


another php code as suggest in that question,

    session_set_cookie_params(0, '/', '.domain-name.local');
    session_start();
    var_dump($_SESSION);

Results : same as second


Any help would be appreciate since i'm stuck here for long time.


EDIT :

When I checked the cookies, I can see two PHPSESSID was created. I think that is the issue. I need to use the same PHPSESSID from the main.


EDIT 2

When I set the session.cookie_domain to .domain-name.local from the php.ini or .htaccess, everything is working fine except in the IE(ie 10/win 8). In IE sometimes session can access sometime web page totally not accessible(keep loading but no result for minutes).

Does anyone was having same experience on the same issue.

</div>

You should try to regenerate the session id:

session_regenerate_id(true);

if session handining work not well, you can write your own via session_set_save_handler(...)

but you need this

@setcookie(
   session_name(),
   session_id(),
   1400069742, // time + TTL
   '/',
   '.domain-name.local',
   false,
   false // use false if you need cookie accessable from javascript
  );