Guest User

Untitled

a guest
Oct 31st, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.63 KB | None | 0 0
  1. <?php
  2.  
  3. include 'config.php';
  4.  
  5. $session_username = $_SESSION['username'];
  6.  
  7. if ($_POST['login'])
  8. {
  9. //get form data
  10. $username = ($_POST['username']);
  11. $password = ($_POST['password']);
  12.  
  13. if (!$username||!$password)
  14. echo "Enter a username and password";
  15. else
  16. {
  17. //log in
  18. $login = mysql_query("SELECT * FROM users WHERE username='$username'");
  19. if (mysql_num_rows($login)==0)
  20. echo "No such user";
  21.  
  22. else
  23. {
  24. while ($login_row = mysql_fetch_assoc($login))
  25. {
  26. //get database password
  27. $password_db = $login_row['password'];
  28.  
  29. //encrypt form password
  30. $password = md5($password);
  31.  
  32. //check password
  33. if ($password!=$password_db)
  34. echo "Incorrect password.";
  35. else
  36. {
  37. $_SESSION['username']=$username; //assign session
  38. header("Location: index.php"); //refresh
  39. }
  40. }
  41.  
  42.  
  43.  
  44. }
  45. }
  46. }
  47. else
  48. {
  49.  
  50. if (isset($session_username))
  51. {
  52. header('Location: me.php');
  53. }
  54. else
  55. {
  56. ?> <html>
  57. <head><title>Login Page</title>
  58. <link href="login.css" rel="stylesheet" type="text/css" />
  59. </head>
  60. <body>
  61. <div class="wrapper">
  62. <div id="top">Online FM</div>
  63. <div id="Box1">
  64. <form action='index.php' method='POST'>
  65. Username:
  66.  
  67. <input type='text' name='username'><p />
  68. Password:
  69.  
  70. <input type='password' name='password'><p />
  71. <input type='submit' name='login' value='Log in'>
  72. </form>
  73. <br />Don't have an account? <a href="register.html"><b>Register one today</b></a>.</div></div>
  74. </body>
  75. </html> <?php
  76. }
  77.  
  78. }
  79.  
  80. ?>
Add Comment
Please, Sign In to add comment