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 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题