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

How to implement different permissions to enter different pages in PHP

Guanhui
Release: 2023-03-01 08:06:01
Original
4331 people have browsed it

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;

?>
Copy after login

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;];

?>
Copy after login

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;
}
?>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template