PHP 5.6.16 is available


(PHP >=5.4.0)

session_statusGibt den Status der aktuellen Sitzung zurück


int session_status ( void )

session_status() wird für die Rückgabe des Status der altuellen Sitzung verwendet.


  • PHP_SESSION_DISABLED wenn die Sitzung deaktiviert ist.
  • PHP_SESSION_NONE wenn Sitzungen aktiviert sind, aber keine existiert.
  • PHP_SESSION_ACTIVE wenn Sitzungen aktiviert sind und eine existiert.

Siehe auch

  • session_start() - Erzeugt eine neue Session oder setzt eine vorhandene fort
add a note add a note

User Contributed Notes 5 notes

coder dot ua at gmail dot com
2 years ago
Universal function for checking session status.

* @return bool
function is_session_started()
    if (
php_sapi_name() !== 'cli' ) {
        if (
version_compare(phpversion(), '5.4.0', '>=') ) {
session_status() === PHP_SESSION_ACTIVE ? TRUE : FALSE;
        } else {
session_id() === '' ? FALSE : TRUE;

// Example
if ( is_session_started() === FALSE ) session_start();
sasi dot viragelet at gmail dot co
9 months ago
Maybe depending on PHP settings, but if return values are not the above, then go for this:
_NONE = 1
php at pointpro dot nl
2 years ago
The advice of ive_insomnia at live dot com should be taken with great care.

First of all, while his use case for session_status is valid, a simpler way to avoid the warning is:

if (!isset($_SESSION)) { session_start(); }

The example of session_status uses the raw values of constants (2 in this case) created specifically for the purpose of not having to use magic numbers.

Better code would be:

if (session_status() !== PHP_SESSION_ACTIVE) {session_start();}

The same can be done using

if (session_id() === "") { session_start(); }

The use of this function is lies more towards status management: change the behavior of a script when sessions are disabled altogether, for example.
1 year ago
If you started and closed a session then test ( session_id() === '' ) to check if a session is active it won't work, session_id() returns an ID even if the session is closed.

Anybody knows another way before PHP 5.4 to check if a session is really not currently active ?
php at kenman dot net
2 years ago
The purpose of this functionality can aid you specifically in cases where code -- prior to your current code -- might have opened a session and then closed it.

Specifically, depending on $_SESSION, session_id(), and the SID constant to determine if a session is active will FAIL if a session has previously been opened & closed within the same request cycle.

Please see the original bug report here:
To Top