Advertisement
Guest User

Untitled

a guest
Jun 10th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.04 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.                 $row['admin'] = $row['user']
  24.  
  25.                 //Transfer row data to the session
  26.                 foreach($row as $k => $v)
  27.                 {
  28.                     $_SESSION[$k] = $v;
  29.                 }
  30.  
  31.                 $_SESSION['user'] = $_POST['username'];
  32.  
  33.                 print '<center><img src="images/loader.gif" /> submitting information..</center>';
  34.                 header("Location: ./");
  35.             }
  36.             else
  37.             {
  38.                 print 'Couldn\'t log you in, please try again.';
  39.                 return;
  40.             }
  41.         }
  42.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement