Advertisement
Guest User

Untitled

a guest
May 10th, 2018
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.73 KB | None | 0 0
  1. <?
  2.          
  3.     // Check if user wants to login (GET info)
  4.     if($_POST['script'] == 'login'){
  5.  
  6.     // That's nice, user wants to login. But lets check if user has filled in all information
  7.     If(empty($_POST['account_username']) OR empty($_POST['account_password'])) {
  8.  
  9.     // At least one of the inputs is empty, display an error
  10.    
  11.     ?>
  12.    
  13.     <p>You need to enter both a username and a password.</p>
  14.    
  15.     <?
  16.    
  17.    
  18.     } else {
  19.  
  20.     // User filled it all in!
  21.  
  22.     // Make variables save with mysql_real_escape_string and sha1
  23.     $ip = $_SERVER['REMOTE_ADDR'];
  24.     $online = '1';
  25.     $referer = $_SERVER['HTTP_REFERER'];
  26.     $username = mysql_real_escape_string($_POST['account_username']);
  27.     $password = SHA1(mysql_real_escape_string($_POST['account_password']));
  28.     mysql_query("SET time_zone = 'CET'");
  29.  
  30.     // Search for a combination
  31.     $query = mysql_query("SELECT * FROM account WHERE username = '" . $username . "' AND sha_pass_hash = '" . $password . "' ") or die(mysql_error());
  32.  
  33.     session_start();
  34.        
  35.     // Save result
  36.     list($user_id) = mysql_fetch_row($query);
  37.    
  38.     }
  39.        
  40.     // If the user_id is empty no combination was found
  41.     if(empty($user_id)) {
  42.  
  43.     ?>
  44.    
  45.     <p>Wrong username or password.</p>
  46.  
  47.     <?
  48.    
  49.     } else {
  50.  
  51.     // Create new session, store the user id
  52.    
  53.     $_SESSION['user_id'] = "$user_id";
  54.            
  55.     $query_online = "UPDATE account SET online='$online', last_ip='$ip', last_login=NOW() WHERE username = '$username'";
  56.     $result_online = mysql_query($query_online);
  57.  
  58.     // Redirect to userpanel.php
  59.    
  60.     $validatedate = uniqid();
  61.     sql("UPDATE acount SET cookie_check='$validate' WHERE id=$user_id");
  62.     setcookie('NEHI_USER', $user_id."|".$validate, time()+60*60*24*365, "/");
  63.    
  64.     print '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$referer.'">';   
  65.    
  66.     }      
  67.  
  68.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement