您当前的位置: 首页 > 慢生活 > 程序人生 网站首页程序人生
webman-session管理-判断对应session数据是否存在
发布时间:2022-01-27 19:44:45编辑:雪饮阅读()
可以使用has方法判斷,对应的session不存在或者对应的session值为null时返回false,否则返回true。
也可以使用exists方法判斷,区别是当对应的session项值为null时,也返回true。
實例:
public function index(Request $request)
{
$session = $request->session();
$session->set("key1","val1");
$session->set("key2",null);
$has = $session->has('key1');
$has2 = $session->has('key2');
$exists1= $session->exists('key1');
$exists2= $session->exists('key2');
return response(var_export(compact("has","has2","exists1","exists2"),true));
}
實例被請求時:
[root@localhost ~]# elinks http://127.0.0.1:8787/blog/index --dump
array ( 'has' => true, 'has2' => false, 'exists1' => true, 'exists2' =>
true, )
关键字词:webman,session,管理,判断,对应,数据,是否,存在