Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //These pages require a certain access level.
- $require_access = array(
- "/community/*" => 97,
- "/community/management/*" => 97,
- "/account/*" => 1,
- "/generate_missing_account_files.php" => 99
- );
- //Loop through the $required_access array looking for any keys that have the recursive symbol '*'.
- foreach($require_access as $key=>$value)
- {
- //Check if this key has the recursive symbol in it.
- $recursive_pos = strpos($key, "*");
- //If the key has a recursive symbol.
- if($recursive_pos!==false)
- {
- //Get the index of this key.
- $recursive_index = array_search($key, $require_access);
- //Remove the key from the array, because it's not in the proper format with the recursive key at the end.
- array_splice($require_access, $recursive_index, 1);
- $document_root = $_SERVER['DOCUMENT_ROOT'];
- $sub_dir = substr($key, 0, $recursive_pos);
- //Add the folder to the array.
- $require_access[$sub_dir] = $value;
- //Scan the directory that the key was refering to.
- $file_list = scandir($document_root.$sub_dir);
- foreach ($file_list as $file)
- {
- //If the folder has the name of '.', '..', or is a directory, skip it.
- if($file == "." || $file==".." || is_dir($document_root.$sub_dir.$file)) continue;
- //Add the file to the array.
- $require_access[$sub_dir.$file] = $value;
- }
- }
- }
- if(isset($require_access[$_SERVER['REQUEST_URI']]))
- {
- if(!isset($_SESSION["group_level"]))
- {
- $_SESSION["group_level"] = 0;
- }
- if($_SESSION["group_level"]<$require_access[$_SERVER['REQUEST_URI']])
- {
- include($_SERVER['DOCUMENT_ROOT'].'/includes/unauthorized.php');
- die();
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement