登录时加载基于角色的导航 [英] Loading role-based navigation upon login

查看:81
本文介绍了登录时加载基于角色的导航的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个登录表单,三种类型的用户之一通过该表单进入网站(基于PHP).登录后,索引页面应根据用户类型加载导航栏.现在,登录页面将在不检查用户类型的情况下加载索引.如何实现呢?

我没有使用任何PHP框架.

解决方案

在登录过程中,将用户的用户类型存储到会话中:

session_start();

// ...

// if the user's login was successful:
$_SESSION["user_type"] = 1; // or similar

然后,您可以在随后的每个页面加载中检查用户的类型并包括相关的导航栏:

session_start();

switch ($_SESSION["user_type"])
{
  case 1:
    // nav type 1
    break;

  default:
    // default navigation bar
    break;
}

别忘了在每个页面上都需要调用session_start(),您需要此信息,尽管我想您还是要这样做,因为您已经有登录用户和未登录用户了!!

I have a login form through which one of three types of users gets into the website (PHP-based). Upon login the index page should load with the navigation bar based on user type. Right now the login page loads the index without checking for user type. How to achieve this?

I'm not using any PHP framework.

解决方案

During the login process, store the user's usertype into the session:

session_start();

// ...

// if the user's login was successful:
$_SESSION["user_type"] = 1; // or similar

then you can check on each subsequent page load what type the user is and include the relevant navigation bar:

session_start();

switch ($_SESSION["user_type"])
{
  case 1:
    // nav type 1
    break;

  default:
    // default navigation bar
    break;
}

Don't forget to call session_start() on each page you need this information, although I'm presuming you're doing that anyway since you have logged-in and non-logged-in users...!

这篇关于登录时加载基于角色的导航的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆