Advertisement
Guest User

Project

a guest
Nov 14th, 2016
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.38 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if(isset($_POST['login'])) {
  5. include_once("db.php");
  6. $username = strip_tags($_POST['username']);
  7. $password = strip_tags($_POST['password']);
  8.  
  9. $username = stripslashes($username);
  10. $password = stripslashes($password);
  11.  
  12. $username = mysqli_real_escape_string($db, $username);
  13. $password = mysqli_real_escape_string($db, $password);
  14.  
  15. $password = md5($password);
  16.  
  17. $sql = "SELECT * FROM users WHERE username='$username' LIMIT 1";
  18. $query = mysqli_query($db, $sql);
  19. $row = mysqli_fetch_array($query);
  20. $id = $row['id'];
  21. $db_password = $row['password'];
  22.  
  23. if($password == $db_password) {
  24. $_SESSION['username'] = $username;
  25. $_SESSION['id'] = $id;
  26. header("Location: index.php");
  27. } else {
  28. echo "You didn't enter the correct details!";
  29. }
  30.  
  31. }
  32. ?>
  33.  
  34. <html>
  35. <head>
  36. <title>Login</title>
  37. </head>
  38. <body>
  39. <h1 style="font-family: Tahoma;">Login</h1>
  40. <form action="login.php" method="post" enctype="multipart/form-data">
  41. <input placeholder="Username" name="username" type="text" autofocus>
  42. <input placeholder="Password" name="password" type="password">
  43. <input name="login" type="submit" value="Login">
  44. </form>
  45. </body>
  46. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement