Compare | objects | process | Experience recently opened a project I previously done, the system structure used 4 include files to the user's permissions to judge, is a typical process-oriented approach, probably many friends have written this code before. I sorted out the code and wrote a simple class of permission judgments to compare the differences between the objects on one side and the process orientation.
The code is as follows (some of the code is omitted).
sesson1.php
<?php
/*
* Function: Gets the user's cookie to determine whether the user is logged in and has system administrator privileges
* Programmer: Xiangli
* Date: 2002-07-19
*/
session2.php
<?php
/*
* Function: Gets the user's cookie to determine whether the user is logged in and has operator privileges
* Programmer: Xiangli
* Date: 2001-07-19
*/
session3.php
<?php
/*
* Function: Obtain the user's cookie to determine whether the user has logged in, whether the user has normal user rights
* Programmer: Xiangli
* Date: 2001-07-19
*/
session4.php
<?php
/*
* Function: Obtain the user's cookie to determine whether the user has logged in, whether the user has enterprise user rights
* Programmer: Xiangli
* Date: 2001-08-11
*/
Merged Permissions Judgment class:
sessionpower.php
<?php
/**
* @ Function: Based on the value of the cookie to determine whether the user has logged in and user permissions
* @ Programmer: Xiangli
* @ Date: 2002-12-20
*/
Class sessionpower{
var username;//user Name
var level;//user Power level
/**
* To determine whether the user has logged in
*/
function Sessionpower ()
{
$this->username = $HTTP _cookie_vars[' UserName '];//username
$this->level = $HTTP _cookie_vars[' level '];//permission levels
/**
* Do you have system administrator privileges
*/
function Adminpower ()
{
if ($HTTP _cookie_vars[' level ']!= 1)
{
Header ("Location:.") /right.phtml ");
}
}
/**
* Do you have operator permissions
*/
function Operatorpower ()
{
if ($this->level > 2)
{
Header ("Location:.") /index.phtml ");
}
}
/**
* Have normal user rights
*/
function Generalpower ()
{
if ($this->level > 3)
{
Header ("Location:./right.phtml");
}
}
/**
* Whether the user has enterprise user rights
*/
function Enterprisepower ()
{
if ($this->level!= 4)
{
#header ("Location:.") /client_login.phtml ");
}
}
}
?>
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.