PHP.mk документација

session_status

Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.

function.session-status.php PHP.net прокси Преводот се освежува
Оригинал на PHP.net
Патека function.session-status.php Локална патека за оваа страница.
Извор php.net/manual/en Оригиналниот HTML се реупотребува и локално се стилизира.
Режим Прокси + превод во позадина Кодовите, табелите и белешките остануваат читливи во истиот тек.
session_status

Референца за `function.session-status.php` со подобрена типографија и навигација.

function.session-status.php

session_status

(PHP 5 >= 5.4.0, PHP 7, PHP 8)

session_status(PHP 5 >= 5.4.0, PHP 7, PHP 8)

= NULL

session_status(): int

session_status() Враќа го тековниот статус на сесијата

Параметри

Оваа функција нема параметри.

Вратени вредности

  • PHP_SESSION_DISABLED ако сесиите се оневозможени.
  • PHP_SESSION_NONE се користи за враќање на тековниот статус на сесијата.
  • PHP_SESSION_ACTIVE ако сесиите се овозможени, но не постои.

Види Исто така

  • session_start() - Започнете нова или продолжи постоечка сесија

Белешки од корисници 9 белешки

ако сесиите се овозможени и постои.
пред 11 години
Maybe depending on PHP settings, but if return values are not the above, then go for this:
_DISABLED = 0
_NONE = 1
_ACTIVE = 2
sasi dot viragelet at gmail dot co
пред 7 години
Use always session_status(), to check if a session is already started and active.
if(session_status() !== PHP_SESSION_ACTIVE) session_start();
or 
if(session_status() === PHP_SESSION_NONE) session_start();

Don't use
if(!isset($_SESSION)) session_start();
or
if(session_id() === "") session_start();

They will not work properly after a call to session_write_close().
Both functions will continue to report, that the session exists.
And this is right, you can read from $_SESSION, but if you want to write,
you need session_start() again.

As a shorthand you can use 
@session_start() 
with the @ at the beginning to suppress the 
PHP notice "A session had already been started - ignoring session_start()"

As stated in the manual for session_start(), a second call will do no harm,
it will be simply ignored. But you need the @, if you don't want to get the notice.
info at eurocron dot de
12 години пред
Universal function for checking session status.

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

// Example
if ( is_session_started() === FALSE ) session_start();
?>
guy dot sartorelli на silverstripe точка com
пред 4 години
Note session_status() is for file based session only.

DB based session status needs to have custom function based on table structure.
coder dot ua at gmail dot com
12 години пред
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:

<?php
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:

<?php
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.
php at pointpro dot nl
Nimja
Numerical Values for
PHP_SESSION_DISABLED  is 0
PHP_SESSION_NONE is 1
PHP_SESSION_ACTIVE is  2
ајон на хиурл точка ком
пред 9 години
This is how the session_status() works:
<?php
function session_status(){
    if(!extension_loaded('session')){
        return 0;
    }elseif(!file_exists(session_save_path().'/sess_'.session_id()){
        return 1;
    }else{
        return 2;
    }
}
?>
tuangson at gmail dot com
12 години пред
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 ?
Ollea
пред 10 години
Just another function to determine whether the session has already started:

function is_session_started () {
    return function_exists ( 'session_status' ) ? ( PHP_SESSION_ACTIVE == session_status () ) : ( ! empty ( session_id () ) ); 
}
На оваа страница

Автоматски outline од активната документација.

Насловите ќе се појават тука по вчитување.

Попрегледно читање

Примерите, changelog табелите и user notes се визуелно издвоени за да не се губат во долгата содржина.

Брз совет Користи го outline-от Скокни директно на главните секции од активната страница.
Извор Оригиналниот линк останува достапен Кога ти треба целосен upstream context, отвори го PHP.net во нов tab.