Advertisement
walter2303

Untitled

Jul 26th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.85 KB | None | 0 0
  1. <?php
  2. session_start();
  3.  
  4. if(isset($_POST['email']) && empty($_POST['email']) == false){
  5.     $email = addslashes($_POST['email']);
  6.     $senha = md5 (addslashes($_POST['senha']));
  7.    
  8.     $dsn="mysql:dbname:blog,host=localhost";
  9.     $dbuser = "root";
  10.     $dbpass = "";
  11.    
  12.     try{
  13.         $db =new PDO($dsn, $dbuser, $dbpass);
  14.    
  15.         $sql = $db->query("Select * from usuarios where email ='$email' and senha ='$senha'");
  16.        
  17.         if($sql->rowCount() >0){
  18.            
  19.             $dado = $sql->fetch();
  20.            
  21.             $_SESSION['id'] = $dado['id'];
  22.             header("Location: index.php");
  23.        
  24.        
  25.         }
  26.        
  27.     }catch(PDOExecption $e){
  28.         echo "Falhou:" .$e->getMessage();
  29.     }
  30.    
  31. }
  32. ?>
  33.  
  34. Pagina de Login
  35.  
  36. <form method="POST">
  37.  
  38.     E-mail:<br/>
  39.     <input type="email" name="email" /><br/><br/>
  40.  
  41.     Senha:<br/>
  42.     <input type="password" name="password" /><br/><br/>
  43.  
  44.     <input type="submit"  value="Entrar" />
  45.  
  46.     </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement