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

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

WBOY
WBOYOriginal
2016-06-13 13:16:28918browse

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

在以前的php 版本中,要判断session是否有效,只能用如下的方法:?

Java代码? ?收藏代码
  1. session_start();??
  2. ????
  3. ??if(isset($_SESSION))??
  4. ??{???
  5. ????echo?"Started";??
  6. ??}??
  7. ??else??
  8. ??{??
  9. ????echo?"Not?Started";??
  10. ??}??



?? 而在php 5.4(即将发行)中,对session的状态进行了细分,可以用如下的方法判断:?

Java代码? ?收藏代码
  1. session_start();??
  2. ????
  3. ??$status?=?session_status();??
  4. ????
  5. ??if($status?==?PHP_SESSION_DISABLED)??
  6. ??{??
  7. ????echo?"Session?is?Disabled";??
  8. ??}??
  9. ??else?if($status?==?PHP_SESSION_NONE?)??
  10. ??{??
  11. ????echo?"Session?Enabled?but?No?Session?values?Created";??
  12. ??}??
  13. ??else??
  14. ??{??
  15. ????echo?"Session?Enabled?and?Session?values?Created";??
  16. ??}??



? 可以看到,通过使用session_status()返回的是一个int类型的值,表示出session的各种状态,比如禁止(PHP_SESSION_DISABLED ),session还不存在?
(PHP_SESSION_NONE)?
,或者session已经被建立起来了(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 _autoload函数用法 Next article: thinkphp栏目治理