Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function reAuth($uri){
- //Separate document name from uri
- //$tokens = explode('/', $uri);
- //$page = end($tokens);
- $abs_us_root=$_SERVER['DOCUMENT_ROOT'];
- $self_path=explode("/", $_SERVER['PHP_SELF']);
- $self_path_length=count($self_path);
- $file_found=FALSE;
- for($i = 1; $i < $self_path_length; $i++){
- array_splice($self_path, $self_path_length-$i, $i);
- $us_url_root=implode("/",$self_path)."/";
- if (file_exists($abs_us_root.$us_url_root.'z_us_root.php')){
- $file_found=TRUE;
- break;
- }else{
- $file_found=FALSE;
- }
- }
- $urlRootLength=strlen($us_url_root);
- $page=substr($uri,$urlRootLength,strlen($uri)-$urlRootLength);
- //bold($page);
- $db = DB::getInstance();
- $id = null;
- //retrieve page details
- $query = $db->query("SELECT id, page, re_auth FROM pages WHERE page = ?",[$page]);
- $count = $query->count();
- if ($count==0){
- bold('<br><br>Page not found. Something went wrong.');
- die();
- }
- $results = $query->first();
- $pageDetails = array( 'id' =>$results->id, 'page' => $results->page, 'private' =>$results->private);
- $pageID = $results->id;
- //If page does not exist in DB, allow access
- if (empty($pageDetails)){
- return true;
- }elseif ($pageDetails['re_auth'] == 0){//If page is public, allow access
- return true;
- }else{ //Authorization is required. Insert your authorization code below.
- echo "Authorization required. Insert code here for that.";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement