How to tell if a session is active?

后端 未结 7 1432
长发绾君心
长发绾君心 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 16:58

    Here's a good drop in replacement that won't break stuff when you move to 5.4:

    if(!function_exists('session_status')){
        function session_active(){
            return defined('SID');   
        }
    }else{
        function session_active(){
            return (session_status() == PHP_SESSION_ACTIVE);   
        }        
    }
    

提交回复
热议问题