Home > php教程 > php手册 > php session 判断:php 5.4中新增加对session状态判断的功能

php session 判断:php 5.4中新增加对session状态判断的功能

WBOY
Release: 2016-06-21 08:51:31
Original
1084 people have browsed it

  在以前的php 版本中,要判断session是否有效,只能用如下的方法:
session_start();
if(isset($_session))
{
echo "started";
}
else
{
echo "not started";
}
   而在php 5.4(即将发行)中,对session的状态进行了细分,可以用如下的方法判断:
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";
}
  可以看到,通过使用session_status()返回的是一个int类型的值,表示出session的各种状态,比如禁止(php_session_disabled ),session还不存在
(php_session_none)
,或者session已经被建立起来了(php_session_active) 本文链接http://www.cxybl.com/html/wlbc/Php/20120607/28693.html



Related labels:
source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template