PHP isset $ _session等于字符串 [英] PHP isset $_session equal to string

查看:73
本文介绍了PHP isset $ _session等于字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我是PHP OOP的新手

So guys I'm new to PHP OOP

我使用角色登录",并创建功能(checkrole)以了解其角色.

I make Login with Roles, and make function(checkrole) for knowing what role it is.

这就是我的功能的样子

public static function hasadmin()
{
  if(session_id() == '') {
  session_start();
  }
  if(isset($_SESSION['role']) == 'A') {
    return true;
  }
}

并将其命名为navbar部分:

and call it into navbar partial :

<?php if (helper::login() == true && helper::hasadmin() == true) { ?>
<li style="float:\right"><a href="?controller=auth&action=logout">Logout</a></li>
<li><a href="?controller=admin&action=petugas">Petugas</a></li>
<li><a href="?">Laporan</a></li>

功能helper::login完美运行. 每次我以其他角色的身份登录时,部分角色(petugas,laporan) 仍然出来.

Function helper::login works perfectly. Every time I login with another role the partial (petugas, laporan) still comes out.

推荐答案

isset返回布尔值.运行isset ,然后检查实际值.

isset returns a boolean. Run the isset and check the actual value.

if(isset($_SESSION['role']) && $_SESSION['role'] == 'A') {

这篇关于PHP isset $ _session等于字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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