Guest User

Untitled

a guest
Oct 23rd, 2017
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2. $host="myhost";
  3. $username="a2512574_user";
  4. $password="password";
  5. $db_name="a2512574_users";
  6. $tbl_name="Persons";
  7.  
  8. // Connect to server and select databse.
  9. mysql_connect("$host", "$username", "$password")or die("cannot connect");
  10. mysql_select_db("$db_name")or die("cannot select DB");
  11.  
  12. // username and password sent from form
  13. $myusername=$_POST['username'];
  14. $mypassword=$_POST['password'];
  15.  
  16. // To protect MySQL injection (more detail about MySQL injection)
  17. $myusername = stripslashes($myusername);
  18. $mypassword = stripslashes($mypassword);
  19. $myusername = mysql_real_escape_string($myusername);
  20. $mypassword = mysql_real_escape_string($mypassword);
  21.  
  22. $sql="SELECT * FROM $tbl_name WHERE username='$myusername' and password='$mypassword'";
  23. $result=mysql_query($sql);
  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. setcookie("username", $myusername, time()+3600);
  32. setcookie("password", $mypassword, time()+3600);
  33. header("location:login_success.php");
  34. }
  35. else {
  36. echo "Wrong Username or Password, Please Try Again";
  37. }
  38. ?>
Add Comment
Please, Sign In to add comment