Advertisement
Guest User

page_auth.php

a guest
Feb 6th, 2016
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.68 KB | None | 0 0
  1. <?php
  2.     //These pages require a certain access level.
  3.     $require_access = array(
  4.         "/community/*" => 97,
  5.         "/community/management/*" => 97,
  6.         "/account/*" => 1,
  7.         "/generate_missing_account_files.php" => 99
  8.     );
  9.  
  10.     //Loop through the $required_access array looking for any keys that have the recursive symbol '*'.
  11.     foreach($require_access as $key=>$value)
  12.     {
  13.        
  14.         //Check if this key has the recursive symbol in it.
  15.         $recursive_pos = strpos($key, "*");
  16.        
  17.         //If the key has a recursive symbol.
  18.         if($recursive_pos!==false)
  19.         {
  20.            
  21.             //Get the index of this key.
  22.             $recursive_index = array_search($key, $require_access);
  23.            
  24.             //Remove the key from the array, because it's not in the proper format with the recursive key at the end.
  25.             array_splice($require_access, $recursive_index, 1);
  26.            
  27.             $document_root = $_SERVER['DOCUMENT_ROOT'];
  28.             $sub_dir = substr($key, 0, $recursive_pos);
  29.            
  30.             //Add the folder to the array.
  31.             $require_access[$sub_dir] = $value;
  32.                
  33.             //Scan the directory that the key was refering to.
  34.             $file_list = scandir($document_root.$sub_dir);
  35.             foreach ($file_list as $file)
  36.             {
  37.                 //If the folder has the name of '.', '..', or is a directory, skip it.
  38.                 if($file == "." || $file==".." || is_dir($document_root.$sub_dir.$file)) continue;
  39.                
  40.                 //Add the file to the array.
  41.                 $require_access[$sub_dir.$file] = $value;
  42.             }
  43.         }
  44.     }
  45.  
  46.     if(isset($require_access[$_SERVER['REQUEST_URI']]))
  47.     {
  48.         if(!isset($_SESSION["group_level"]))
  49.         {
  50.             $_SESSION["group_level"] = 0;
  51.         }
  52.         if($_SESSION["group_level"]<$require_access[$_SERVER['REQUEST_URI']])
  53.         {
  54.             include($_SERVER['DOCUMENT_ROOT'].'/includes/unauthorized.php');
  55.             die();
  56.         }
  57.     }
  58. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement