How to tell if a session is active?

后端 未结 7 1435
长发绾君心
长发绾君心 2020-11-27 16:20

Per request, there are a few different ways that you can tell whether or not a session has been started, such as:

$isSessionActive = (session_id() != \"\");
         


        
7条回答
  •  情书的邮戳
    2020-11-27 17:07

    The following code only dumps one session_id() for me, not two

    session_start();
    echo session_id();
    session_destroy();
    echo session_id();
    

    If you're having difficulties with this still you can try creating a variable to check, that you destroy when you destroy the session.

    session_start();
    $_SESSION['intialized'] = 'This will not print';
    $_SESSION = array(); // Unset all variables
    session_destroy();
    echo $_SESSION['initialized']; // No output
    

提交回复
热议问题