Advertisement
Guest User

Untitled

a guest
Aug 5th, 2017
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.61 KB | None | 0 0
  1. function reAuth($uri,$uid){
  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, 're_auth' => $results->re_auth);
  42.     $pageID = $results->id;
  43.  
  44.     //If page does not exist in DB, allow access
  45.     if (empty($pageDetails)){
  46.         return true;
  47.     }elseif ($pageDetails['re_auth'] == 0){//If page is public, allow access
  48.         return true;
  49.     }else{ //Authorization is required.  Insert your authorization code below.
  50.  
  51.     verifyadmin($uid,$page);
  52.  
  53.   }
  54. }
  55.  
  56. function verifyadmin($id,$page) {
  57. $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
  58. $db = DB::getInstance();
  59.   $findUserQ = $db->query("SELECT last_confirm FROM users WHERE id = ?",array($id));
  60.   $findUser = $findUserQ->first();
  61.   //get the current time
  62.     $current=date("Y-m-d H:i:s");
  63.  
  64.   //convert the string time to a time format php can use
  65.     $ctFormatted = date("Y-m-d H:i:s", strtotime($current));
  66.  
  67.   //convert the db time to a time format php can use
  68.     $dbTime = strtotime($findUser->last_confirm);
  69.  
  70.   //take the db time and add 2 hours to it.
  71.     $dbPlus = date("Y-m-d H:i:s", strtotime('+2 hours', $dbTime));
  72.  
  73.   //See what you've got, uncomment this
  74.         // echo $ctFormatted;
  75.         // echo '<br>';
  76.         // echo $dbPlus;
  77.         // echo '<br>';
  78.  
  79.  
  80.   if (strtotime($ctFormatted) > strtotime($dbPlus)){
  81.     Redirect::to('/usersc/adminverify.php?actual_link='.$actual_link.'&page='.$page);
  82.   }
  83.   else
  84.   {
  85.       $db = DB::getInstance();
  86.       $db->query("UPDATE users SET last_confirm = ? WHERE id = ?",array($current,$id));
  87.   }
  88. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement