A simple comparison of process-oriented and object-oriented (personal experience)!

Source: Internet
Author: User
Tags date comparison empty header
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
*/

$UserName = $HTTP _cookie_vars[' UserName1 '];//username
if (Empty ($UserName) | | | $HTTP _cookie_vars[' level ')!= 1)
{
Header ("Location:.") /right.phtml ");
}
?>

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
*/

$UserName = $HTTP _cookie_vars[' UserName1 '];//username
$Level = $HTTP _cookie_vars[' level '];//permission levels

if (Empty ($UserName) | | $Level > 2)
{
Header ("Location:.") /index.phtml ");
}
?>

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
*/

if (Empty ($UserName 1) | | $Level > 3)
{
Header ("Location:./right.phtml");
}
?>

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
*/

if (Empty ($_cookie[' clientname ')) | | $_cookie[' level ']!= 4)
{
#header ("Location:.") /client_login.phtml ");
}
?>

Call:
?
Include_once ("/lib/session1.php");
Include_once ("/lib/session2.php");
Include_once ("/lib/session3.php");
Include_once ("/lib/session4.php");
?>

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

if ($this->username = "" | | $this->level = "")
{
Header ("Location:.") /index.phtml ");
}
}

/**
* 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 ");
}
}
}
?>

Call:
?
Include_once ("/lib/sessionpower.php");
$sessionPower = new Sessionpower ();
$sessionPower->adminpower ();
$sessionPower->operatorpower ();
$sessionPower->generalpower ();
$sessionPower->enterprisepower ();
?>

Note: If you are using object-oriented programming, it is recommended that you use the Zend Editor, which is a lot quicker to develop!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.