PHP Classes

File: protect.php

Recommend this page to a friend!
  Classes of Igor Feghali   Power 2 Protect   protect.php   Download  
File: protect.php
Role: Auxiliary script
Content type: text/plain
Description: Protection script
Class: Power 2 Protect
Restrict user access to pages based on permissions
Author: By
Last change: Accessible without user login
Date: 17 years ago
Size: 2,107 bytes
 

Contents

Class file image Download
<?

/* #INFO############################################
Author: Igor Feghali
(c) 2003-2006, ifeghali@interveritas.net
----------------------------------------------------
This file is part of Power 2 Protect Class
----------------------------------------------------
################################################# */

/* #DESCRIPTION#####################################
Verifies if logged user has access to the current
web page. This file must be included in all the
files you want to protect.
################################################# */

// #INCLUDES########################################
include("config.inc.php");
include(
"permissions.class.php");
// #################################################

// #CHECK SESSION###################################
if (!isset($_SESSION["usercode"]))
{
   
header("location: ".$location_accessdenied);
    exit;
}
// #################################################

// #COUNT THE NUMBER OF USER TYPES##################
$sql = "select * from $table_usertype";
$result = mysql_query($sql,$con) or die (mysql_error());
$howmany_usert = mysql_num_rows($result);
// #################################################

// #GET THE SETTINGS FOR THE CURRENT PAGE###########
$sql = "select accesskey from $table_perm where page ='".$PHP_SELF."'";
$result = mysql_query($sql,$con) or die (mysql_error());
// #################################################

// #INSTANTIATES CLASS##############################
$permtable = new permissions;
// #################################################

// #VERIFY ACCESS ONLY IF WE HAVE PERMISSIONS SET###
if (mysql_num_rows($result) > 0)
{
   
$row = mysql_fetch_array($result);
    if (!
$permtable->get($row["accesskey"],$usertype,$howmany_usert))
    {
       
header("location: ".$location_accessdenied);
        exit;
    }
}
// #################################################

// #CLEAN UP THE HOUSE##############################
unset($sql);
unset(
$result);
unset(
$howmany_usert);
unset(
$row);
unset(
$permtable);
// #################################################

?>