Advertisement
Guest User

Untitled

a guest
Mar 10th, 2017
159
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.43 KB | None | 0 0
  1. function reAuth($uri){
  2.     //Separate document name from uri
  3.     //$tokens = explode('/', $uri);
  4.     //$page = end($tokens);
  5.  
  6.     $abs_us_root=$_SERVER['DOCUMENT_ROOT'];
  7.  
  8.     $self_path=explode("/", $_SERVER['PHP_SELF']);
  9.     $self_path_length=count($self_path);
  10.     $file_found=FALSE;
  11.  
  12.     for($i = 1; $i < $self_path_length; $i++){
  13.         array_splice($self_path, $self_path_length-$i, $i);
  14.         $us_url_root=implode("/",$self_path)."/";
  15.  
  16.         if (file_exists($abs_us_root.$us_url_root.'z_us_root.php')){
  17.             $file_found=TRUE;
  18.             break;
  19.         }else{
  20.             $file_found=FALSE;
  21.         }
  22.     }
  23.  
  24.     $urlRootLength=strlen($us_url_root);
  25.     $page=substr($uri,$urlRootLength,strlen($uri)-$urlRootLength);
  26.  
  27.     //bold($page);
  28.  
  29.     $db = DB::getInstance();
  30.     $id = null;
  31.  
  32.     //retrieve page details
  33.     $query = $db->query("SELECT id, page, re_auth FROM pages WHERE page = ?",[$page]);
  34.     $count = $query->count();
  35.     if ($count==0){
  36.         bold('<br><br>Page not found. Something went wrong.');
  37.         die();
  38.     }
  39.     $results = $query->first();
  40.  
  41.     $pageDetails = array( 'id' =>$results->id, 'page' => $results->page, 'private' =>$results->private);
  42.  
  43.     $pageID = $results->id;
  44.    
  45.     //If page does not exist in DB, allow access
  46.     if (empty($pageDetails)){
  47.         return true;
  48.     }elseif ($pageDetails['re_auth'] == 0){//If page is public, allow access
  49.         return true;
  50.     }else{ //Authorization is required.  Insert your authorization code below.
  51.  
  52. echo "Authorization required. Insert code here for that.";
  53.    
  54.   }
  55. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement