Advertisement
Guest User

Untitled

a guest
Oct 4th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. <?php
  2. ob_start();
  3. $host="localhost"; // Host name
  4. $username="root"; // Mysql username
  5. $password="root"; // Mysql password
  6. $db_name="users"; // Database name
  7. $tbl_name="access"; // Table name
  8.  
  9. // Connect to server and select databse.
  10. mysql_connect("localhost","root","") or die("cannot connect");
  11. mysql_select_db("$db_name")or die("cannot select DB");
  12.  
  13. $username=$_POST['username'];
  14. $password=$_POST['password'];
  15.  
  16. // To protect MySQL injection (more detail about MySQL injection)
  17. $username = stripslashes($username);
  18. $password = stripslashes($password);
  19. $username = mysql_real_escape_string($username);
  20. $password = mysql_real_escape_string($password);
  21.  
  22. $sql="SELECT * FROM $tbl_name WHERE username= '$username' and password='$password'";
  23.  
  24. $result=mysql_query($sql);
  25. $count=mysql_num_rows($result);
  26.  
  27. if($count==1){
  28. // Register $myusername, $mypassword and redirect to file "home.php"
  29. session_register("username");
  30. session_register("password");
  31. header("location:home.php");
  32. }
  33. else {
  34. echo "Wrong Username or Password";
  35. }
  36.  
  37. ob_end_flush();
  38. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement