PHP登录系统


Login System in PHP

我创建了一个完全可用的登录系统,并使用了cookie。但在我的数据库中,我有不同类型的用户,希望用户登录时显示不同的页面。我该怎么做?

alert("无效的电子邮件或密码,请重试!");window.history.go(-1);';}?>

在数据库中创建一个名为"usertype"的字段然后,当您显示页面时,只需对用户类型进行if检查,并为每个用户类型显示正确的页面。

 if($user->usertype=='your_usertype1'){
    header('location: http://www.yoursite.com/dashboard1');
 } else if($user->usertype=='your_usertype2'){
    header('location: http://www.yoursite.com/dashboard2');
 } else {
    header('location: http://www.yoursite.com/dashboarddefault');
 }

显然,在实际的页面上,你也需要进行检查,这样,如果用户转到该页面,而他们不是那种类型的用户,他们就会被重定向回或重定向到你想要的任何地方。

例如,在dashboard1.php页面上,您将看到。

 if($_SESSION['user']['usertype']!='your_usertype1'){
    header('location: http://www.yoursite.com/'); // direct back if the user isnt of this type
 }

您可以根据用户类型强制HTTP header Location。假设$type是您的用户类型:

switch($type) {
  case 1:
    header('Location: user.php');
    break;
  case 2:
    header('Location: admin.php');
    break;
  case 3:
    header('Location: superadmin.php');
    break;
}