Home  >  Article  >  Backend Development  >  How to implement different permissions to enter different pages in PHP

How to implement different permissions to enter different pages in PHP

Guanhui
GuanhuiOriginal
2020-05-14 15:44:314319browse

How to implement different permissions to enter different pages in PHP

How to implement different permissions to enter different pages in PHP

First, when the user logs in successfully, add the user's permission level to the Session session ;

<?php

$user_perm_level = 1;

session_start();

$_SESSION[&#39;user_perm_level&#39;] = $user_perm_level;

?>

Then when accessing the page, take out the permission level stored in the Session;

<?php
session_start();

$user_perm_level = $_SESSION[&#39;user_perm_level&#39;];

?>

Finally, jump to the corresponding page according to the permission level.

<?php
session_start();

$user_perm_level = $_SESSION[&#39;user_perm_level&#39;];

switch($user_perm_level){
  case 1:
    header("location: topage1.php");
    break;
  case 2:
    header("location: topage2.php");
    break;
  case 3:
    header("location: topage3.php");
    break;
  default:
    header("location: topage.php");
    break;
}
?>

Recommended tutorial: "PHP Tutorial"

The above is the detailed content of How to implement different permissions to enter different pages in PHP. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn