download20151010 2017-04-26 16:18
浏览 17

管理员链接无法访问管理员链接,其显示给所有其他用户的onyl管理员角色可以看到管理员链接

This first is panel.php file and second is session file and 3rd is login.php file file. I want panel.php file shows only if logged user is administrator then show only admin links and if other then show other links. i don't know what happened with this code i tried but it showing all links to all users . kindly find the error please

panel.php file

   <?php
   include('session.php');
   ?>
    <!DOCTYPE html>
   <html>
   <head>
    <title></title>
  </head>
     <body>
    <?php
          if($_SESSION['role']=='Administrator')
          { 
          ?>
       <li><a href="#">Add Publisher</a></li>
    <?php
          }else{ 
          ?>

    <li><a href="#">Mailbox</a></li>
    <?php
          } 
      ?>
     </body>
     </html>

session.php file

   <?php

    $connection = mysql_connect("localhost", "root", "");
    $db = mysql_select_db("simple_db", $connection);
    session_start();// Starting Session
    // Storing Session
    $user_check=$_SESSION['login_user'];
    $role_check=$_SESSION['role'];

    // SQL Query To Fetch Complete Information Of User
    $ses_sql=mysql_query("SELECT * FROM simple_db WHERE email_n='$user_check' ", $connection);
    $row = mysql_fetch_assoc($ses_sql);
    $login_session =$row['email_n'];

    if(!isset($login_session)){
    mysql_close($connection); // Closing Connection
    header('Location: login.php'); // Redirecting To Home Page
     }
     ?>

login.php file

<?php
            session_start(); // Starting Session
            $error=''; // Variable To Store Error Message
            if (isset($_POST['submit'])) {
            if (empty($_POST['email_n']) || empty($_POST['email_p'])) {
            $error = "Email or Password is invalid";
            }
            else
            {
            // Define $username and $password
            $email_n = $_POST['email_n'];
            $email_p = $_POST['email_p'];
            // Establishing Connection with Server by passing server_name, user_id and password as a parameter
            $connection = mysql_connect("localhost", "root", "");
            // To protect MySQL injection for Security purpose
            $email_n = stripslashes($email_n);
            $email_p = stripslashes($email_p);
            $email_n = mysql_real_escape_string($mail_n);
            $email_p = mysql_real_escape_string($email_p);
            // Selecting Database
            $db = mysql_select_db("simple_db", $connection);
            // SQL query to fetch information of registerd users and finds user match.
            $query = mysql_query("SELECT * FROM simple_db WHERE email_n='$email_n' AND email_p = '$email_p' ", $connection);
            $rows = mysql_num_rows($query);
            if ($rows == 1) {

            $_SESSION['login_user']=$email_n;
            $_SESSION['role']=$row->Role;

             // Initializing Session
            header("location: panel.php"); // Redirecting To Other Page
            } else {
            $error = "Email or Password is invalid";

            }
            mysql_close($connection); // Closing Connection
            }
            }
            ?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 HLs设计手写数字识别程序编译通不过
    • ¥15 Stata外部命令安装问题求帮助!
    • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
    • ¥15 TYPCE母转母,插入认方向
    • ¥15 如何用python向钉钉机器人发送可以放大的图片?
    • ¥15 matlab(相关搜索:紧聚焦)
    • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
    • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
    • ¥50 需求一个up主付费课程
    • ¥20 模型在y分布之外的数据上预测能力不好如何解决