Advertisement
Guest User

Untitled

a guest
May 11th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.25 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password="exik"; // Mysql password
  6. $db_name="realmd"; // Database name
  7. $tbl_name="account"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. // Define $myusername and $mypassword
  14. $myusername=$_POST['myusername'];
  15. $mypassword=$_POST['mypassword'];
  16.  
  17. // To protect MySQL injection (more detail about MySQL injection)
  18. $pass = sha1(strtoupper($myusername).":".strtoupper($mypassword));
  19.  
  20. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and sha_pass_hash='$pass'";
  21. $result=mysql_query($sql);
  22. $row = mysql_fetch_array($result);
  23. $row['gmlevel'] = $_SESSION['gmlevel'];
  24.  
  25. // Mysql_num_row is counting table row
  26. $count=mysql_num_rows($result);
  27. // If result matched $myusername and $mypassword, table row must be 1 row
  28.  
  29. if($count==1){
  30. // Register $myusername, $mypassword and redirect to file "login_success.php"
  31. session_register("myusername");
  32. session_register("mypassword");
  33. header("location:login_success.php");
  34. }
  35. else {
  36. echo "Wrong Username or Password <a href='main_login.php'>Zpet</a>";
  37. }
  38.  
  39. ob_end_flush();
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement