dora12345678 2017-10-13 23:10
浏览 56
已采纳

我遇到了让两个用户访问管理页面的问题

I am having an issue trying to get two users or more to access the admin page. I tried adding a || between them but it does not work for either of them. User here in the example is xgrh and zeap. Any help would be appreciated not sure what I am doing wrong.

<?php 
    session_start();

    if (!isset($_SESSION['uid']) || $_SESSION['lanId'] != 'xgrh'|| $_SESSION['lanId'] != 'zeap') {
        header('refresh:2;url=http://a0319p528/dc399supplies/index.php');

        echo "
        <div class='container'>
            <div class='panel panel-danger'>
                <div class='panel-heading'> <h3>Access Denied!!  You will now be redirected back</h3></div>
                <div class='panel-body'><img src='../admin.jpg'></div>
            </div>
        </div>";                 
    }
?>
  • 写回答

1条回答 默认 最新

  • dongxuanchao1425 2017-10-13 23:45
    关注

    As per your example code, to check if the user is not signed in, and not one of the two allowed... this would work:

    if ( !isset($_SESSION['uid']) or 
         ( $_SESSION['lanId'] != 'xgrh' and $_SESSION['lanId'] != 'zeap' ) )
    {
        ... denied code ...
    }
    

    Checks first if no one is set. Then if neither are the right user.

    If either of those two cases are true (thus the mixed 'or' and 'and'), then they are denied access.

    You can also do it like this:

    if ( !isset($_SESSION['uid']) or !in_array($_SESSION['lanId'],array('xgrh','zeap')) )
    {
        ... denied code ...
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改
  • ¥20 wireshark抓不到vlan
  • ¥20 关于#stm32#的问题:需要指导自动酸碱滴定仪的原理图程序代码及仿真
  • ¥20 设计一款异域新娘的视频相亲软件需要哪些技术支持
  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥15 键盘指令混乱情况下的启动盘系统重装
  • ¥40 复杂的限制性的商函数处理