douzai6337 2018-10-10 04:35
浏览 26
已采纳

会话结构或不同的用户组

I am working on a project in which I have several admins and one Super Admin. The tables have the fields username.password, location & status. I have also created a common table for Admins.

For Admin I need the username and location in session, however, for Super Admin I need just username in session. I have also created a single login page.

The PHP code is as shown below

<?php

include("connect.php");
session_start();
$Username = $_POST["t1"];
$Password = $_POST["t2"];
$Status = $_POST["t3"];
$location = $_POST["l1"];
$q = mysql_query("select * from admin_login where username='$Username'");
$rs = mysql_fetch_row($q);

if (($rs[0] == $Username) && ($rs[1] == $Password) && ($rs[4] == $location) && ($rs[3] == $Status)) {
    if ($_SESSION["status"] = admin) {
        $_SESSION["user"] = $Username;
        $_SESSION["location"] = $location;
        echo "<script type='text/javascript' language='javascript'>
        alert('Admin logged in successfully');
        </script>";
        header("Refresh:0;http://localhost/e_classified/admin/a_activity.php");
    } else {
        echo "<script type='text/javascript' language='javascript'>
        alert('Incorrect details, Enter correct details');
        </script>";
        header("Refresh:0;http://localhost/e_classified/super admin/login.html");
    }
}
if (($rs[0] == $Username) && ($rs[1] == $Password) && ($rs[3] == $Status)) {
    if ($_SESSION["status"] == sadmin) {
        $_SESSION["user"] = $Username;
        echo "<script type='text/javascript' language='javascript'>
        alert('Super Admin logged in successfully');
        </script>";
        header("Refresh:0;http://localhost/e_classified/super%20admin/s_activity.php");
    } else {
        echo "<script type='text/javascript' language='javascript'>
        alert('Incorrect details, Enter correct details');
        </script>";
        header("Refresh:0;http://localhost/e_classified/super admin/login.html");

    }

}

The problem is that while logging in for any Admin/Super Admin it opens in in the same window (ex. s_activity.php).

  • 写回答

1条回答 默认 最新

  • douji0108 2018-10-10 17:49
    关注

    try this code:

    if($_SESSION["status"] == "admin") {
        $_SESSION["user"] = $Username;
        $_SESSION["location"] = $location;
        echo "<script type='text/javascript' language='javascript'>
    ";
        echo "alert('Admin logged in successfully');
    ";
        echo "</script>
    "; 
        header("Refresh:0;http://localhost/e_classified/admin/a_activity.php");
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 cad图纸,chx-3六轴码垛机器人
  • ¥15 移动摄像头专网需要解vlan
  • ¥20 access多表提取相同字段数据并合并
  • ¥20 基于MSP430f5529的MPU6050驱动,求出欧拉角
  • ¥20 Java-Oj-桌布的计算
  • ¥15 powerbuilder中的datawindow数据整合到新的DataWindow
  • ¥20 有人知道这种图怎么画吗?
  • ¥15 pyqt6如何引用qrc文件加载里面的的资源
  • ¥15 安卓JNI项目使用lua上的问题
  • ¥20 RL+GNN解决人员排班问题时梯度消失