Advertisement
betinhosilva

Untitled

Apr 27th, 2017
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.02 KB | None | 0 0
  1. <?php
  2. // inclui o arquivo de inicialização
  3. include_once('assets/conn/init.php');
  4.  
  5. // resgata variáveis do formulário
  6. $email = isset($_POST['email']) ? $_POST['email'] : '';
  7. $password = isset($_POST['senha']) ? $_POST['senha'] : '';
  8. // cria o hash da senha
  9. $passwordHash = make_hash($password);
  10.  
  11. $PDO = db_connect();
  12. $sql = "SELECT * FROM usuarios WHERE email = :email AND senha = :password";
  13. $stmt = $PDO->prepare($sql);
  14. $stmt->bindParam(':email', $email);
  15. $stmt->bindParam(':password', $passwordHash);
  16. $stmt->execute();
  17.  
  18. $users = $stmt->fetchAll(PDO::FETCH_ASSOC);
  19.  
  20. //Se o email não existir na base de dados gera um alerta
  21. if (count($users) <= 0):
  22.     header('Location: index.php?msg=1');
  23.     exit;
  24. endif;
  25.  
  26. // pega o primeiro usuário
  27. $user = $users[0];
  28.  
  29. session_start();
  30. $_SESSION['logged_in'] = true;
  31. $_SESSION['user_id'] = $user['usuario_id'];
  32. $_SESSION['nome'] = $user['nome'];
  33. $_SESSION['email'] = $user['email'];
  34. $_SESSION['nivel_usuario'] = $user['nivel_usuario'];
  35.  
  36. header('Location: home.php');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement