Advertisement
Guest User

Untitled

a guest
Aug 12th, 2017
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2.    
  3.     abstract class Banco{
  4.           protected $conexao;
  5.           protected $user='root';
  6.           protected $pass='rootx';
  7.           protected $dsn='mysql:hostname=localhost;dbname=loja';
  8.  
  9.           public function __construct(){
  10.             $this->conexao = new PDO($this->dsn,$this->user,$this->pass);
  11.           }
  12.           public function inserir($sql){
  13.             return $this->conexao->exec($sql);
  14.           }
  15.           public function listar($sql){
  16.             return $this->conexao->query($sql);
  17.           }
  18.     }
  19. ?>/
  20.  
  21. //----------------------------------------------------------------------
  22. <?php
  23.     class Usuario extends Banco{
  24.  
  25.         private $nome;
  26.         private $telefone;
  27.         private $email;
  28.         private $senha;
  29.         private $id;
  30.  
  31.         // exibir
  32.         public function exibir($campos='*',$where=null){
  33.             $sql = "SELECT $campos FROM usuario $where";
  34.             return $this->listar($sql);
  35.         }
  36.        
  37.         // login
  38.         public function login($usuario='',$senha=''){
  39.  
  40.             $where = "WHERE email='$usuario' AND senha='$senha'";
  41.             $validar = true;
  42.  
  43.             foreach($this->exibir('*',$where) as $usuario){
  44.                 $_SESSION['usuario'] = $usuario;
  45.                 $validar = false;
  46.                 header('location: listar_livro.php');
  47.                 exit;
  48.             }
  49.             if($validar){
  50.                 $msg = 'Usuário e/ou senha errado(s)';
  51.                 header('location: login.php?msg='.$msg);
  52.             }
  53.         }
  54.     }
  55. ?>
  56.  
  57.  
  58.  
  59. //----------------------------------------------------------------------
  60. <br>
  61. <form action='logar.php' method='post'>
  62.     e-mail: <input type='text' name='email'/>
  63.     <br/>
  64.     Senha: <input type='password' name='senha'/>
  65.     <input type='submit' value='login'/>
  66. </form>
  67.  
  68. <?php if($_GET['msg']){ echo $_GET['msg'];}?>
  69.  
  70. //----------------------------------------------------------------------
  71.  
  72. <?php
  73.     session_star();
  74.     require_once 'Banco.class.php';
  75.     require_once 'Usuario.class.php';
  76.  
  77.     $u = new Usuario();
  78.     $u->login($_POST['email'],$_POST['senha']);
  79. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement