How to tell if a session is active?

后端 未结 7 1434
长发绾君心
长发绾君心 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:11

    I worked around this by adding a couple wrapper functions around the various session creation/closing/destroying functions. Basically:

    function open_session() {
         session_start();
         $_SESSION['is_open'] = TRUE;
    }
    
    function close_session() {
       session_write_close();
       $_SESSION['is_open'] = FALSE;
    }
    
    function destroy_session() {
       session_destroy();
       $_SESSION['is_open'] = FALSE;
    }
    
    function session_is_open() {
       return($_SESSION['is_open']);
    }
    

    Hackish, but accomplished what I needed.

提交回复
热议问题