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 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?