Home  >  Article  >  Backend Development  >  PHP 5.4 adds the function of judging session status

PHP 5.4 adds the function of judging session status

巴扎黑
巴扎黑Original
2016-11-23 15:17:381069browse

In previous php versions, to determine whether the session is valid, you can only use the following method:

Java code

session_start();

if(isset($_SESSION))

{

echo "Started";

}

else

{

echo "Not Started";

}

In php 5.4 (forthcoming), the status of the session is To subdivide, you can use the following Method judgment:


Java code

session_start();

$status = session_status();

if($status == PHP_SESSION_DISABLED)

{

echo "Session is Disabled";

}

else if($status == PHP_SESSION_NONE)

{

echo "Session Enabled but No Session values ​​Created";

}

else

{

echo "Session Enabled and Session values ​​Created" ;

}

You can see that by using session_status(), an int type value is returned, indicating various statuses of the session, such as prohibited (PHP_SESSION_DISABLED), session does not exist yet

(PHP_SESSION_NONE)

, Or the session has been established (PHP_SESSION_ACTIVE)



Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:php regular length limitNext article:php regular length limit