php - 登录时重定向到不同页面 - php

标签 php mysql session

我想将管理员重定向到一个页面,并将其他用户重定向到另一个页面。 可以在 procedure 中执行,但不能在 oop 中执行。 管理员可能会添加新用户并显示他们有很多工作要做,而用户只能看到他/她的页面。

<?php
require_once('userClass.php'); 
$userObj = new USER(); 
session_start();
$type = $_GET['type'];


if(empty($type) || !isset($type)) {

  echo 'Request type is not set';

} else if($type == 'signup') {

   $data =  USER::addNewUser($_REQUEST);
   $_SESSION = $data;
   if($data['status'] == 'error') {
     header("location:register.php");
   } else {
     header("location:index.php");
   }
} else if($type == 'login') {
   $username = addslashes($_REQUEST['username']);
   $password = addslashes($_REQUEST['password']);
   $_SESSION =  USER::login($username, $password);
   if($_SESSION['status'] == 'error') {
     header("location:index.php");
   } 
   else {

     header("location:profile.php");

   }
   /*if($_SESSION['username'] == 'admin@admin.com') {
     header("location:admin.php");
   } 
   else {

     header("location:profile.php");

   }*/


} else if($type == 'logout') {
 unset($_SESSION);
 session_destroy();
 header("location:index.php");
}


?>

正在寻找解决方案......请帮忙。 *查看代码中的注释部分。

最佳答案

最简单的方法之一就是定义角色。

例如

if($_SESSION['username'] == 'admin@admin.com' && $_POST['role'] = 'admin'){
       header("location:admin.php");
 } 
 else {

 header("location:profile.php");
}

关于php - 登录时重定向到不同页面 - php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47767830/

相关文章:

php - 为什么login.php一直显示密码无效?

php - 计数数组 DISTINCT 以上 1

php - 我试图在 <form> 的 Action 字段中了解 PHP_SELF 与 ProcessForm.php

mysql - 为什么 MySQL 卡在这个简单的子查询上?

ruby-on-rails - 检测设计 session 何时过期

security - CSRF token 的生存期应达到多长时间?

php - 缺少半小时时区

python - 多个数据中心

python - Django 中用户的默认类型是什么?

ios - 如何将字符串值传递给我应用程序中的所有 ViewController