Advertisement
Guest User

Untitled

a guest
Nov 15th, 2017
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. //Inserisco i dati nel DB
  2. $nome = $_GET['nome'];
  3. $cognome = $_GET['cognome'];
  4. $email = $_GET['email'];
  5. $username = $_GET['username'];
  6. $password = $_GET['password'];
  7. $hash = password_hash($password, PASSWORD_BCRYPT);
  8. $sql = "INSERT INTO clienti (nome, cognome, email, username, password)
  9. VALUES (:nome, :cognome, :email, :username, :password)";
  10. $req = $dbh->prepare($sql);
  11. $req->execute(
  12. array(
  13. ":nome" => $nome,
  14. ":cognome" => $cognome,
  15. ":email" => $email,
  16. ":username" => $username,
  17. ":password" => $hash,
  18. )
  19. );
  20.  
  21.  
  22.  
  23. //login
  24.  
  25. require_once 'includes/connect-db.php';
  26.  
  27. session_start();
  28. $_SESSION['loggato'] = false;
  29.  
  30. $username = $_REQUEST['username'];
  31. $password = $_REQUEST['password'];
  32.  
  33. $sql = "SELECT * FROM clienti WHERE username = :username AND password = :password";
  34. $req = $dbh->prepare($sql);
  35.  
  36. $req->execute(
  37. array(
  38. ":username" => $_REQUEST['username'],
  39. ":password" => $_REQUEST['password']
  40. )
  41. );
  42.  
  43. $utente = $req->fetch(PDO::FETCH_ASSOC);
  44.  
  45. if($utente != null) {
  46. $_SESSION['loggato'] = true;
  47. $_SESSION['utente'] = $utente;
  48. Header('Location: index.php');
  49. } else {
  50. Header('Location: login.php?error=true');
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement