Advertisement
Guest User

Untitled

a guest
May 29th, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. LOGIN.PHP
  2. [
  3. <html>
  4. <body>
  5.  
  6. <form action="checklogin.php" method="post">
  7. Username: <input type="text" name="myusername" />
  8. Password: <input type="text" name="mypassword" />
  9. <input type="submit" value="Login" />
  10. </form>
  11.  
  12. </html>
  13. </body>
  14.  
  15. ]
  16.  
  17. CHECKLOGIN.PHP
  18. [
  19. <html>
  20. <body>
  21. <?php
  22. error_reporting(E_ALL);
  23. ini_set('display_errors', true);
  24. $host=”127.0.0.1”; // Host name
  25. $username=”root”; // Mysql username
  26. $password=”root"; // Mysql password
  27. $db_name=”freelobby”; // Database name
  28. $tbl_name=”login”; // Table name
  29.  
  30. // Connect to server and select databse.
  31. mysql_connect(”$host”, “$username”, “$password”)or die(”cannot connect”);
  32. mysql_select_db(”$db_name”)or die(”cannot select DB”);
  33.  
  34. // username and password sent from form
  35. $myusername=$_POST['myusername'];
  36. $mypassword=$_POST['mypassword'];
  37.  
  38. // To protect MySQL injection
  39. $myusername = stripslashes($myusername);
  40. $mypassword = stripslashes($mypassword);
  41. $myusername = mysql_real_escape_string($myusername);
  42. $mypassword = mysql_real_escape_string($mypassword);
  43.  
  44. $sql=”SELECT * FROM $tbl_name WHERE username=’$myusername’ and password=’$mypassword’”;
  45. $result=mysql_query($sql);
  46.  
  47. // Mysql_num_row is counting table row
  48. $count=mysql_num_rows($result);
  49. // If result matched $myusername and $mypassword, table row must be 1 row
  50.  
  51. if($count==1){
  52. // Register $myusername, $mypassword and redirect to file “login_success.php”
  53. session_register(”myusername”);
  54. session_register(”mypassword”);
  55. header(”location:login_success.php”);
  56. }
  57. else {
  58. echo “Wrong Username or Password”;
  59. }
  60. ?>
  61. </html>
  62. </body>
  63. ]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement