How to tell if a session is active?

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

    See edits to the original question; basically, PHP 5.4 and above now has a function called session_status() to solve this problem!

    "Expose session status via new function, session_status" (SVN Revision 315745)

    If you need this functionality in a pre-PHP 5.4 version, see hakre's answer.

提交回复
热议问题