Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.23 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. $host = "lolhost";
  4. $db_name = "loldbname";
  5. $user = "loluser";
  6. $password = "lolpassword";
  7. $tbl_name="loltable"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect("$host", "$user", "$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.  
  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. // Register $myusername, $mypassword and redirect to file "login_success.php"
  33. session_register("myusername");
  34. session_register("mypassword");
  35. session_register();
  36. header("location:login_success.php");
  37. }
  38. else {
  39. echo "Invalid username or password";
  40. }
  41.  
  42. ob_end_flush();
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement