Can You Switch PHP Sessions In a Session?

前端 未结 7 1776
情深已故
情深已故 2020-12-09 19:31

I have two apps that I\'m trying to unify. One was written by me and another is a CMS I am using. My authentication happens in the one I coded and I\'d like my CMS to know t

7条回答
  •  不知归路
    2020-12-09 20:26

    It is possible. But I think you have to do the session handling yourself:

    session_name('foo');
    // start first session
    session_start();
    
    // …
    
    // close first session
    session_write_close();
    
    session_name('bar');
    // obtain session id for the second session
    if (ini_get('session.use_cookies') && isset($_COOKIE[session_name()])) {
        session_id($_COOKIE[session_naem()]);
    } else if (ini_get('session.use_trans_sid') && !ini_get('session.use_only_cookies') && isset($_REQUEST[session_name()])) {
        session_id($_REQUEST[session_naem()]);
    }
    // start second session
    session_start();
    
    // …
    

    But note that you might do some of the other session handling things like cookie setting as well. I don’t know if PHP does this in this case too.

提交回复
热议问题