检查 PHP 会话是否处于活动状态; [英] Check if a PHP session is active;

查看:43
本文介绍了检查 PHP 会话是否处于活动状态;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

基本上我想要实现的是这个,下面的不起作用,但你应该明白.

Basically what I am trying to achieve is this, the below does not work but you should get the idea.

if (session_status() == PHP_SESSION_ACTIVE) {
  show specific icons
}
else
{
  don't show specific icons
}

我做错了什么.如何可靠地检查会话是否在 php 5.4 中启动.我在某处读到这是推荐的方法.

What am I doing wrong. How can I reliably check if a session is started in php 5.4. I have read somewhere that this is the recommended way.

推荐答案

session_status 适用于 PHP v5.4 及更高版本,也许这就是原因.

session_status is available for PHP v5.4 and later, maybe that's why.

您可以尝试使用 session_id :

session_id() 返回当前会话的会话 ID,如果没有当前会话(当前会话 ID 不存在),则返回空字符串 ("").

session_id() returns the session id for the current session or the empty string ("") if there is no current session (no current session id exists).

正是您在 5.4 以下 PHP 所需要的!;)

Just what you need for PHP below 5.4 ! ;)

这篇关于检查 PHP 会话是否处于活动状态;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆