简体   繁体   English

IF ELSE语句中的PHP逻辑或运算符

[英]PHP Logical OR Operator in an IF ELSE Statement

I have a user level login system and I want all the login users to go to the home page. 我有一个用户级登录系统,我希望所有登录用户都可以转到主页。 I wonder why the following logic not working. 我不知道为什么以下逻辑不起作用。 Please suggest better ways. 请提出更好的方法。

$role = $_SESSION['sess_userlevel'];

if( $role == 1 || $role == 2 || $role == 3 ){
        $securep = '../';
        header('Location: '.$securep);
 }else{
  //back to the login page.
}

The problem with this code is that it redirects back to the login page. 此代码的问题在于它重定向回登录页面。

maybe you have to insert 也许你必须插入

session_start();

before you access the $_SESSION array? 在访问$_SESSION数组之前?

Also check the result of 同时检查结果

var_dump($role)

before your if statement 在您的if语句之前

$role = $_SESSION['sess_userlevel'];

if( $role == 1 || $role == 2 || $role == 3 ){
    $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER['DOCUMENT_ROOT']";
          header('location:'.$actual_link.'yourpathfile.php');
 }else{
  //back to the login page.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM