Allow php sessions to carry over to subdomains

前端 未结 10 1416
清歌不尽
清歌不尽 2020-11-22 01:10

I use php sessions (not cookies, except for session id cookie) for all user data, and when a user goes to their profile user.mydomain.com they are immediately \"logged out\"

10条回答
  •  我寻月下人不归
    2020-11-22 01:54

    if(isset($_COOKIE['session_id']))
        session_id($_COOKIE['session_id']);
        Zend_Session::start(); //or session_start();
    
        if(!isset($_COOKIE['session_id']))
            setcookie('session_id', session_id(), 0, '/', '.yourdomain.com');
    

    This is a good solution, but you cannot use it in all situations. For examples it will not work when you cannot rely on not-session cookies.

    This actually MUST work if you use it correctly.

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

    For example you need to put it before session_start() and also in all files that call session_start()

提交回复
热议问题