Advertisement
Guest User

Untitled

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