SHARE
TWEET

Untitled

a guest Oct 4th, 2017 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. ob_start();
  4. $host="localhost"; // Host name
  5. $username="root"; // Mysql username
  6. $password=""; // Mysql password
  7. $db_name="gamerlogo"; // Database name
  8. $tbl_name="users"; // Table name
  9.  
  10. // Connect to server and select databse.
  11. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  12. mysql_select_db("$db_name")or die("cannot select DB");
  13.  
  14. // Define $myusername and $mypassword
  15. $myusername=$_POST['myusername'];
  16. $mypassword=$_POST['mypassword'];
  17.  
  18. // To protect MySQL injection (more detail about MySQL injection)
  19. $myusername = stripslashes($myusername);
  20. $mypassword = stripslashes($mypassword);
  21. $myusername = mysql_real_escape_string($myusername);
  22. $mypassword = mysql_real_escape_string($mypassword);
  23.  
  24. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  25. $result=mysql_query($sql);
  26.  
  27. // Mysql_num_row is counting table row
  28. $count=mysql_num_rows($result);
  29. // If result matched $myusername and $mypassword, table row must be 1 row
  30.  
  31. if($count==1){
  32.  
  33. $assoc = mysql_fetch_assoc($result);
  34. $myid = $assoc["uid"];
  35. // Register $myusername, $mypassword and redirect to file "login_success.php"
  36. session_start();
  37. $_SESSION['myusername'] = $myusername;
  38. $_SESSION['mypassword'] = $mypassword;
  39. $_SESSION['uid'] = $myid;
  40. header('location:login_success.php');
  41. }
  42. else {
  43. echo "Wrong Username or Password, please return to the previous page and try again.";
  44. }
  45.  
  46. ob_end_flush();
  47. ?>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top