Home  >  Article  >  Backend Development  >  php 5.4中新增加对session状态判断的效能

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

WBOY
WBOYOriginal
2016-06-13 12:34:00883browse

php 5.4中新增加对session状态判断的功能
  在以前的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)

1 楼 lijichao 2012-02-20  
 php 5.4中新增加对session状态判断的效能

2 楼 mailangel123 2012-02-21  
这个可以有。

3 楼 mailangel123 2012-02-21  
[color=red][/color]
[/align][/size][align=center]
[/align][align=right][size=x-small][align=left][/align]
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