Advertisement
Guest User

Untitled

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