dox19458 2018-01-24 22:32
浏览 18
已采纳

会话if语句在一个页面上工作而在另一个页面上工作

Before we start, I'm a beginner. I'm sure it's a simple solution but just not for me.

I'm using a session so no one can't access an admin page unless they're an admin.

The code is:

  1. if ( $_SESSION['admin'] != 1 ) {
  2. $_SESSION['message'] = "You're not admin!";
  3. header("location: ../error.php");
  4. }

Which works perfectly. regular users can't access it but admins can. BUT.

In my main cpanel I want to have a button linking to the admin panel that will only appear if the user is admin. I did the same piece of code:

  1. if ( $_SESSION['admin'] != 1 ) {
  2. echo '<a href="admin/index.php"><button class="butto button-bloc" name="admin"/>Admin Panel</button></a>';
  3. }

Problem is, it seems like the button shows up whether the user is an admin or not and now I think that my code is just trying to make me blow my lid as I spent a full hour trying to find what the f-- is on the go.

Any help would be greatly appreciated! I'm sure someone who's good with PHP will have it solved in under a minute lol

  • 写回答

3条回答 默认 最新

  • duannian7116 2018-01-24 22:40
    关注

    The condition you have written is same for user who is admin and not an admin

    Please check the condition

    For having a button linking to the admin panel that will only appear if the user is admin.

    if ( $_SESSION['admin'] == 1 ) { // you have written $_SESSION['admin'] != 1
    echo '<a href="admin/index.php"><button class="butto button-bloc" name="admin"/>Admin Panel</button></a>';
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 设计一个光控计数器,全部用ttl芯片
  • ¥15 vscode platformio
  • ¥15 代写uni代码,app唤醒
  • ¥15 全志t113i启动qt应用程序提示internal error
  • ¥15 ensp可以看看嘛.
  • ¥80 51单片机C语言代码解决单片机为AT89C52是清翔单片机
  • ¥60 优博讯DT50高通安卓11系统刷完机自动进去fastboot模式
  • ¥15 minist数字识别
  • ¥15 在安装gym库的pygame时遇到问题,不知道如何解决
  • ¥20 uniapp中的webview 使用的是本地的vue页面,在模拟器上显示无法打开
手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部