PHP Classes

Power 2 Protect: Restrict user access to pages based on permissions

Recommend this page to a friend!

  Author Author  
Picture of Igor Feghali
Name: Igor Feghali <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 39
All time rank: 32327 in Brazil Brazil
Week rank: 118 Up10 in Brazil Brazil Up


  Detailed description   Download Download .zip .tar.gz   Install with Composer Install with Composer  
This package is meant to restrict the access of users to the Web pages of a site according to a definition of user role based permissions stored in a database.

The users are authenticated in login form when they try to access a protected page.

If a user attempts to access a page to which he as no permission, the browser is redirected to access an error page.

Each protected protected Web page has an entry in the database that establishes an association with an integer key value that defines the roles of users that are authorized to access the page.

The access key value defines a bit mask. Each bit is associated to user role. A bit in the access key mask set to 1 determines that the users with that role have access to the page.

Details
Power 2 Protect PHP Class Author: Igor Feghali Email: ifeghali@interveritas.net [DESCRIPTION] This class verifies if a user have access to the current page by requesting a mysql database record and then take the user to a error page if the record doesn't match the user's key. [MySQL TABLE STRUCTURE REQUIRED OR EQUIVALENT] USERTYPE PERMISSIONS ($table_usertype) ($table_perm) |---------------| |---------------|---------------| |usertype(int) | |accesskey(int) |page(char) | |---------------| |---------------|---------------| | 2^0 | | x |/dir/page1.php | | 2^1 | | y |/dir2/page2.php| | ... | | z |page3.php | | 2^(n-1) | | w |/dir3/page4.php| |---------------| |---------------|---------------| USER ($table_user) |-------------|-----------|---------|-------------------| |usercode(int)|login(char)|pwd(char)|usertype(int) | |-------------|-----------|---------|-------------------| | 1 | login1 | pwd1 | 2^a | | 2 | login2 | pwd2 | 2^b | |-------------|-----------|---------|-------------------| [[WHERE]] "n" is the number of records in USERTYPE. a,b is an integer and 2^a and 2^b must have a correspondent in USERTYPE. x,y,z,w is an integer [0,1,2,3,7,...,2^(n-1)] and is obtained by the sum of the usertypes you want to grant access. Note: you must provide the whole path after your domain's root dir. Example: for a script located at www.yourdomain.com/dir1/script.php you should fill "page" with "/dir1/script.php". [INSTALL] Edit file config.inc.php. Create the tables USERTYPE, PERMISSIONS and USER (or the names you set on the variables) following the model under the MySQL table structure topic of this document. If you want to use the default table names, you can run the script create_tables.sql to automatically create them. Make sure you gave MYSQLUSER access to MYSQLDB. [SETUP PROTECTION] Add user types to USERTYPE using powers of 2. Add to PERMISSIONS the relative path to the file you want to protect associated to an accesskey obtained by the sum of the usertypes you wish to grant access. Include the file protect.php in the script you have just added to PERMISSIONS. [EXAMPLES] For table examples you can check file create_tables.sql. For an example on how to protect a page you can check the file admin.php.

  Classes of Igor Feghali  >  Power 2 Protect  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: Power 2 Protect
Base name: power2
Description: Restrict user access to pages based on permissions
Version: 1.0.0
PHP version: -
License: GNU General Public License (GPL)
All time users: 3572 users
All time rank: 934
Week users: 1 user
Week rank: 113 Up
 
  Groups   Rate classes User ratings   Applications   Files Files  

  Groups  
Group folder image Databases Database management, accessing and searching View top rated classes
Group folder image User Management User records, authentication and session handling View top rated classes


  User ratings  
RatingsUtility Consistency Documentation Examples Tests Videos Overall Rank
All time: Good (87%) Sufficient (75%) Sufficient (62%) Not sure (56%) - - Sufficient (63%) 1036
Month: Not yet rated by the users

  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  Files folder image Files  
File Role Description
Accessible without login Plain text file admin.php Example Protected Example Page
Accessible without login Plain text file config.inc.php Conf. Config File
Accessible without login Plain text file create_tables.sql Data Mysql Example Database
Accessible without login Plain text file error_access.php Example Access Denied Page
Accessible without login Plain text file index.php Appl. Login Form Page
Accessible without login Plain text file logout.php Example Logout script
Accessible without login Plain text file permissions.class.php Class Power 2 Protect Class
Accessible without login Plain text file protect.php Aux. Protection script
Accessible without login Plain text file README Doc. README
Accessible without login Plain text file verify_login.php Appl. Validates information submitted from login form

Install with Composer Install with Composer - Download Download all files: power2.tar.gz power2.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
  Files folder image Files  
File Role Description
Accessible without login Plain text file admin.php Example Protected Example Page
Accessible without login Plain text file config.inc.php Conf. Config File
Accessible without login Plain text file create_tables.sql Data Mysql Example Database
Accessible without login Plain text file error_access.php Example Access Denied Page
Accessible without login Plain text file index.php Appl. Login Form Page
Accessible without login Plain text file logout.php Example Logout script
Accessible without login Plain text file permissions.class.php Class Power 2 Protect Class
Accessible without login Plain text file protect.php Aux. Protection script
Accessible without login Plain text file README Doc. README
Accessible without login Plain text file verify_login.php Appl. Validates information submitted from login form

Install with Composer Install with Composer - Download Download all files: power2.tar.gz power2.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.