Unset a specefic session using session id

前端 未结 4 1942
醉梦人生
醉梦人生 2020-12-11 08:13

I am the admin of the the site.I want unset a particular session, i know its session id

The users just stating the session like this

session_id(\"us         


        
4条回答
  •  南方客
    南方客 (楼主)
    2020-12-11 08:57

    Answer by Jack Luo on php.net

    $session_id_to_destroy = 'nill2if998vhplq9f3pj08vjb1';
    // 1. commit session if it's started.
    if (session_id()) {
        session_commit();
    }
    
    // 2. store current session id
    session_start();
    $current_session_id = session_id();
    session_commit();
    
    // 3. hijack then destroy session specified.
    session_id($session_id_to_destroy);
    session_start();
    session_destroy();
    session_commit();
    
    // 4. restore current session id. If don't restore it, your current session will refer     to the session you just destroyed!
    session_id($current_session_id);
    session_start();
    session_commit();
    

提交回复
热议问题