Advertisement
Guest User

Untitled

a guest
Jun 9th, 2017
729
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.65 KB | None | 0 0
  1. <?php
  2.  
  3.     function first(&$array)
  4.     {
  5.         if(!is_array($array)) return null;
  6.         if(!count($array)) return null;
  7.         reset($array);
  8.         return key($array);
  9.     }
  10.    
  11.     $var = first($_GET);
  12.     if(isset($var)) echo 'It\'s working!';
  13.    
  14. class site
  15. {
  16.    
  17.     private static $t = 'template/';
  18.     private static $p = 'pages/';  
  19.  
  20.     public static function load()
  21.     {
  22.  
  23.         include site::$t.'header.php';
  24.  
  25.         if(isset($_SESSION['user']))
  26.         {
  27.             //Is there a URL input?
  28.             if(count($_GET) > 0)
  29.             {
  30.                 echo 'lololo';
  31.  
  32.                 //Get the page's name
  33.                 $page = array_keys($_GET); //Allows the ?index, ?login, etc.. usage
  34.                 $page = $page[0];
  35.             }
  36.  
  37.             else $page = 'index.php';
  38.             include site::$p.$page;
  39.         }
  40.         else include site::$p.'login.php';
  41.  
  42.         include site::$t.'footer.php';
  43.     }
  44.  
  45.     public static function login()
  46.     {
  47.         if(isset($_POST['login']))
  48.         {
  49.             if(empty($_POST['username']))
  50.             {
  51.                 print 'Username field was empty, please try again.';
  52.                 return;
  53.             }
  54.  
  55.             if(empty($_POST['password']))
  56.             {
  57.                 print 'Password field was empty, please try again.';
  58.                 return;
  59.             }
  60.  
  61.             echo '<center><img src="images/loader.gif" /> submitting information..</center>';
  62.  
  63.             $username = mysql_real_escape_string($_POST['username']);
  64.             $password = mysql_real_escape_string($_POST['password']);
  65.             $encrypt = sha1(strtoupper($username.':'.$password));
  66.             $q = mysql_query("SELECT * FROM users WHERE username = '$username' AND password = '$encrypt'") or die(mysql_error());
  67.            
  68.             if(mysql_fetch_array($q) > 0)
  69.             {
  70.                 $row = mysql_fetch_assoc($q);
  71.  
  72.                 foreach($row as $k => $v)
  73.                 {
  74.                     $_SESSION[$k] = $v;
  75.                 }
  76.             }
  77.  
  78.             header('Location:./');
  79.         }
  80.     }
  81.  
  82. }
  83. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement