Guest User

Untitled

a guest
Dec 2nd, 2016
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. <?php
  2. session_start();
  3. ?>
  4.  
  5. <form method="POST">
  6. E-mail: <input type='email' name='email'>
  7. Senha: <input type='password' name='senha'>
  8. <input type="submit" value='submit'>
  9. </form>
  10.  
  11. <?php
  12. if( !empty($_POST['email']) && isset($_POST['email']) && !empty($_POST['senha']) && isset($_POST['senha']) ){
  13. $email = addslashes($_POST['email']);
  14. $senha = md5($_POST['senha']);
  15.  
  16. try{
  17. $dsn = 'mysql:dbname=blog;host=localhost';
  18. $dbuser = 'root';
  19. $dbpass = 'root';
  20.  
  21. $pdo = new PDO($dsn,$dbuser,$dbpass);
  22. $sql = $pdo->query("SELECT * FROM usuarios WHERE email='$email' and senha='$senha'");
  23.  
  24. if($sql->rowCount() > 0){
  25. $dado = $sql->fetch();
  26.  
  27. $_SESSION['id'] = $dado['id'];
  28.  
  29. header("Location: index.php");
  30.  
  31. } else {
  32. print 'Usuário e/ou senha incorretos.';
  33. }
  34. }catch(PDOException $e){
  35. print 'error: '.$e->getMessage();
  36. }
  37. }
  38. ?>
Add Comment
Please, Sign In to add comment