Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1.     public static function login()
  2.     {
  3.         if(isset($_POST['username']))
  4.         {
  5.             if(empty($_POST['username']))
  6.             {
  7.                 print 'Username field was empty, please try again.';
  8.                 return;
  9.             }
  10.  
  11.             if(empty($_POST['password']))
  12.             {
  13.                 print 'Password field was empty, please try again.';
  14.                 return;
  15.             }
  16.  
  17.             $encrypt = sha1(strtoupper($_POST['username'].':'.$_POST['password']));
  18.             $q = mysql_query("SELECT * FROM users WHERE user = '$_POST[username]' AND password = '$encrypt' LIMIT 1") or die(mysql_error());
  19.            
  20.             if(!mysql_num_rows($q) == 0)
  21.             {      
  22.                 $row = mysql_fetch_assoc($q); //We only need one result, so ditch the while
  23.  
  24.                 //CHANGE THE 'rank' TO THE ADMIN FIELD!!!
  25.                 $row['admin'] = $row['rank'];
  26.  
  27.                 //Transfer row data to the session
  28.                 foreach($row as $k => $v)
  29.                 {
  30.                     $_SESSION[$k] = $v;
  31.                 }
  32.  
  33.                 $_SESSION['user'] = $_POST['username'];
  34.  
  35.                 print '<center><img src="images/loader.gif" /> submitting information..</center>';
  36.                 header("Location: ./");
  37.             }
  38.             else
  39.             {
  40.                 print 'Couldn\'t log you in, please try again.';
  41.                 return;
  42.             }
  43.         }
  44.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement