doulian5857 2016-12-31 19:31
浏览 9
已采纳

具有不同权限的mySQLi和PHP登录系统

I'm pretty new to PHP and I need to make a login system and I need to check if the user has certain permission, then show something on the page. Let me give a pseudo-code example:

IF USER HAS PERMISSION "CONTACTS" OR USER HAS PERMISSION "ALL"
  SHOW CONTACTS LINK

I've been using DevDojo's php login script, and I wanted something similar or an adaption of that code with a multi-level system. I've tried many things here on SO but none of them really fit my needs, I need to use something like if $user->hasPermission("contacts"). because as I have many features, levels like 1, 2 and etc. won't fit, and admin or not also won't. I'm pretty newbie, so explanation is welcome! Thanks in advance.

  • 写回答

1条回答 默认 最新

  • 普通网友 2017-01-01 07:40
    关注

    If you have 3 different levels of user with 3 being the master level...

    When the user logs in, set a PHP variable to the permission value set in the database.

    Create your template containing all visible content. Decide which sections will be hidden to users at each level and use PHP if statements to prevent blocks being loaded to the page.

    A very basic example would be

    <?php $level=2; ?>
    
    <img src="http://someimg.com/img.jpg" alt="level 1">
    
    <?php if($level >= 2){ ?>
     <img src="http://someimg.com/img.jpg" alt="level 2">
    <?php }
    
    if($level == 3){?>
     <img src="http://someimg.com/img.jpg" alt="level 3">
    <?php }?>
    

    In this example the variable $level represents the user level, this is followed by 3 images. The first image is available to all level users, the second image is available to user level 2 & above and the third is only visible to master level users. You can see the changes when you change "$level=2" to a value of 1 or 3.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 plotBAPC画图出错
  • ¥30 关于#opencv#的问题:使用大疆无人机拍摄水稻田间图像,拼接成tif图片,用什么方法可以识别并框选出水稻作物行
  • ¥15 Python卡尔曼滤波融合
  • ¥20 iOS绕地区网络检测
  • ¥15 python验证码滑块图像识别
  • ¥15 根据背景及设计要求撰写设计报告
  • ¥20 能提供一下思路或者代码吗
  • ¥15 用twincat控制!
  • ¥15 请问一下这个运行结果是怎么来的
  • ¥15 单通道放大电路的工作原理