NOVINKA: Najžiadanejšie rekvalifikačné kurzy teraz s 50% zľavou + kurz AI ZADARMO. Nečakaj, táto ponuka dlho nevydrží! Zisti viac:

PHP - session_status

Trieda

Koreň \ Bez triedy

Metóda - session_status

(PHP >= 5.4.0)

The function is used to get the status of the current session.

Procedurálne

Parametre

Žiadne

Mávratovej hodnoty

Vracia: int

The function returns the value of one of the following constants:

  • PHP_SESSION_DISABLED (0) if sessions are disabled. This situation is not very common. If you want to disable sessions, you have to do it in the PHP configuration.
  • PHP_SESSION_NONE (1) if sessions are enabled, but there is no active session (for example when session_start() wasn't called yet, or the session was destroyed).
  • PHP_SESSION_ACTIVE (2) if sessions are enabled and there is the active session (when session_start() was called and the session is active)

Príklady

Getting the current session status info:

<?php
session_save_path('.'); // Setting our compiler, ignore this


switch (session_status())
{
    case PHP_SESSION_DISABLED:
        echo 'Session is disabled!';
        break;
    case PHP_SESSION_NONE:
        session_start();
        echo 'Session is enabled, starting new session!' . "\n";
    case PHP_SESSION_ACTIVE:
        echo 'The current session ID is ' . session_id();
        break;
}

Example of PHP_SESSION_NONE:

<?php
session_save_path('.'); // Setting our compiler, ignore this


session_status() . "\n"; // 1 = PHP_SESSION_NONE | We can't use echo() there, because it would send headers!
session_start();
echo session_status() . "\n"; // 2 = PHP_SESSION_ACTIVE
session_destroy();
echo session_status() . "\n"; // 1 = PHP_SESSION_NONE

Súvisiace manuály

      Aktivity