Advertisement
Guest User

Untitled

a guest
Apr 12th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. $host="localhost"; // Host name
  4. $username="xxxxx"; // Mysql username
  5. $password="xxxx="; // Mysql password
  6. $db_name="xxxx"; // Database name
  7. $tbl_name="xxxx"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. $con = new mysqli("$host", "$username", "$password","$db_name")or die("cannot connect");
  11.  
  12. // Define $myusername and $mypassword
  13. $myusername=$_POST['myusername'];
  14. $mypassword=$_POST['mypassword'];
  15.  
  16. // To protect MySQL injection (more detail about MySQL injection)
  17. $myusername = stripslashes($myusername);
  18. $mypassword = stripslashes($mypassword);
  19. $myusername = mysqli_real_escape_string($con , $myusername);
  20. $mypassword = mysqli_real_escape_string($con , $mypassword);
  21.  
  22. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  23. $result=mysqli_query($con , $sql);
  24.  
  25. // Mysql_num_row is counting table row
  26. $count=mysqli_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.  
  32. $_SESSION['myusername']= "$myusername";
  33. $_SESSION['mypassword']= "$mypassword";
  34. header("location:login_success.php");
  35. }
  36. else {
  37. echo "Wrong username or password!";
  38. }
  39.  
  40. ob_end_flush();
  41. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement