Function name: session_status()
Applicable version: PHP 5.4.0 and above
Function description: The session_status() function is used to get the status of the current session. The session state can be one of three:
Syntax: session_status()
Example:
// 检查会话状态$status = session_status(); if ($status == PHP_SESSION_DISABLED) { echo "会话功能已禁用"; } elseif ($status == PHP_SESSION_NONE) { echo "当前没有会话"; } elseif ($status == PHP_SESSION_ACTIVE) { echo "当前有活动会话"; }
In the above example, first use the session_status() function to obtain the status of the current session, and then perform corresponding processing based on the returned status value. If the session function is disabled, the output is "Session function is disabled"; if there is currently no session, the output is "No session currently"; if there is currently active session, the output is "There is currently active session".
Note that before using the session_status() function, the session_start() function must be called to start the session. Otherwise, the session status cannot be obtained correctly.