Advertisement
Guest User

Untitled

a guest
Mar 1st, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.36 KB | None | 0 0
  1. <?php
  2. if (!isset($_POST['username']) || !isset($_POST['password']))
  3. {
  4. ?>
  5. <html>
  6. <head>
  7. <title>Login</title>
  8. </head>
  9. <body>
  10. <form method="POST" action="login.php">
  11. Username <input name="username" type="text"><br>
  12. Password <input name="password" type="password"><br><br>
  13. <input type="submit" value="Accedi">
  14. </form>
  15. </body>
  16. </html>
  17. <?php
  18. }
  19. else
  20. {
  21. ?>
  22. <html>
  23. <head>
  24. <title>Login</title>
  25. </head>
  26. <body>
  27. <?php
  28. $username = $_POST['username'];
  29. $password = $_POST['password'];
  30. if (strlen($username) != 0 && strlen($password) != 0)
  31. {
  32. $connection = @ new mysqli("localhost","root","","biblioteca");
  33. $query = "SELECT * FROM utenti WHERE username = '$username'";
  34. $result = @ $connection->query($query);
  35. if($connection->errno){
  36. @ $connection->close();
  37. die("Errore nell'esecuzione della query");
  38. }
  39. if($connection->errno){
  40. @ $connection->close();
  41. die("Errore nell'esecuzione della query");
  42. }
  43. if (@$result->num_rows == 0)
  44. {
  45. echo "Utente $username sconosciuto: ";
  46. echo "<a href=\"http://localhost/marco/login.php\">riprova.</a><br>";
  47. }
  48. else
  49. {
  50. $user_row = @$result->fetch_array();
  51. $password = crypt($password,0);
  52. if ($password == $user_row['password'])
  53. {
  54. echo "Password corretta: ";
  55. echo "<a href=\"http://localhost/marco/biblioteca.php\">accedi.</a><br>";
  56. session_start();
  57. session_unset();
  58. session_destroy();
  59. session_start();
  60. $_SESSION['username'] = $username;
  61. $_SESSION['start_time'] = time();
  62. $_SESSION['DB_username'] = $user_row['DB_username'];
  63. $_SESSION['Db_password'] = $user_row['DB_password'];
  64. echo "<a href=\"http://localhost/marco/logout.php\"> [$username logout]</a>";
  65. }
  66. else
  67. {
  68. echo "Password errata: ";
  69. echo "<a href=\"http://localhost/marco/login.php\">riprova.</a>";
  70. }
  71. }
  72. @ $result->free();
  73. @ $connection->close();
  74. }
  75. else
  76. {
  77. echo "Username/password non validi: ";
  78. echo "<a href=\"http://localhost/marco/login.php\">riprova.</a>";
  79. }
  80. ?>
  81. </body>
  82. </html>
  83. <?php
  84. }
  85. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement