dismiss Step into the future! Click here to switch to the beta php.net site
downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

session_unregister> <session_start
[edit] Last updated: Fri, 28 Jun 2013

view this page in

session_status

(PHP >=5.4.0)

session_statusReturns the current session status

Description

int session_status ( void )

session_status() is used to return the current session status.

Return Values

  • PHP_SESSION_DISABLED if sessions are disabled.
  • PHP_SESSION_NONE if sessions are enabled, but none exists.
  • PHP_SESSION_ACTIVE if sessions are enabled, and one exists.

See Also



session_unregister> <session_start
[edit] Last updated: Fri, 28 Jun 2013
 
add a note add a note User Contributed Notes session_status - [3 notes]
up
3
php at pointpro dot nl
2 months 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:

<?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.
up
4
ive_insomnia at live dot com
4 months ago
simple session_start() request to avoid warning:

<?php
if (!$_SESSION) {session_start();}
// your code
?>
Or similar code works, but give a warning.

<?php
if(session_status() != 2) {session_start();}
// your code
?>
This option work fine without warning.

0 = PHP_SESSION_DISABLED
1 = PHP_SESSION_NONE
2 = PHP_SESSION_ACTIVE
up
0
adrian
7 days ago
>The use of this function is lies more towards status management: change the behavior of a script when sessions are disabled altogether, for example.

On that note:
<?php
if( session_status() === PHP_SESSION_NONE ){ session_start(); }
?>

This way, you won't try to start a session if a) a session already exists, or b) sessions are disabled.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites