Guest User

Untitled

a guest
Jan 26th, 2018
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.82 KB | None | 0 0
  1. <?php
  2. session_start();
  3. $user=false;
  4. $pass=false;
  5.  
  6. if(!isset($_SESSION["username"])){
  7. if(isset($_POST["username"]))
  8. if(empty($_POST["username"]))
  9. echo "inserisci username </br>";
  10. else{
  11. $username=$_POST["username"];
  12. $user=true;
  13. }
  14. if(isset($_POST["password"]))
  15. if(empty($_POST["password"]))
  16. echo "inserisci password </br>";
  17. else{
  18. $password=$_POST["password"];
  19. $password=md5($password);
  20. $pass=true;
  21. }
  22.  
  23. if($user && $pass){
  24. $connessione=mysql_connect("localhost","root","");
  25. $ris=mysql_query("use sito",$connessione);
  26. $ris=mysql_query("select username from utenti where username='".$username."' && password='".$password."'",$connessione);
  27. if(mysql_num_rows($ris)>0){
  28. $_SESSION['username']= $username;
  29. $_SESSION['password']= $password;
  30. header("location: homepage.php");
  31. }
  32. else
  33. echo "username o password non corretti";
  34. }
  35. }//fine if
  36. else
  37. header("location: homepage.php");
  38.  
  39. if(isset($_POST["logout"])) {
  40. session_destroy();
  41. session_unset("username");
  42. session_unset("password");
  43. }
  44. if(isset($_POST["remove"])) {
  45. $connessione=mysql_connect("localhost","root","");
  46. $ris=mysql_query("use sito",$connessione);
  47. $ris=mysql_query("delete from utenti where username='".$_SESSION["username"]."'",$connessione);
  48. session_destroy();
  49. session_unset("username");
  50. session_unset("password");
  51. }
  52. ?>
  53. <!DOCTYPE html>
  54. <html>
  55. <head>
  56. <title>Login</title>
  57. </head>
  58. <body>
  59. <h1>Accedi</h1>
  60. <form action="login.php" method="POST">
  61. Inserire username:
  62. <input type="text" name="username"></br></br>
  63. Inserire password:
  64. <input type="password" name="password"></br></br>
  65. <input type="submit" value="Login">
  66. </form>
  67. </br>
  68. <a href="registrati.php">Non sei registrato? Registrati</a>
  69. </body>
  70. </html>
Add Comment
Please, Sign In to add comment