Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- abstract class Banco{
- protected $conexao;
- protected $user='root';
- protected $pass='rootx';
- protected $dsn='mysql:hostname=localhost;dbname=loja';
- public function __construct(){
- $this->conexao = new PDO($this->dsn,$this->user,$this->pass);
- }
- public function inserir($sql){
- return $this->conexao->exec($sql);
- }
- public function listar($sql){
- return $this->conexao->query($sql);
- }
- }
- ?>/
- //----------------------------------------------------------------------
- <?php
- class Usuario extends Banco{
- private $nome;
- private $telefone;
- private $email;
- private $senha;
- private $id;
- // exibir
- public function exibir($campos='*',$where=null){
- $sql = "SELECT $campos FROM usuario $where";
- return $this->listar($sql);
- }
- // login
- public function login($usuario='',$senha=''){
- $where = "WHERE email='$usuario' AND senha='$senha'";
- $validar = true;
- foreach($this->exibir('*',$where) as $usuario){
- $_SESSION['usuario'] = $usuario;
- $validar = false;
- header('location: listar_livro.php');
- exit;
- }
- if($validar){
- $msg = 'Usuário e/ou senha errado(s)';
- header('location: login.php?msg='.$msg);
- }
- }
- }
- ?>
- //----------------------------------------------------------------------
- <br>
- <form action='logar.php' method='post'>
- e-mail: <input type='text' name='email'/>
- <br/>
- Senha: <input type='password' name='senha'/>
- <input type='submit' value='login'/>
- </form>
- <?php if($_GET['msg']){ echo $_GET['msg'];}?>
- //----------------------------------------------------------------------
- <?php
- session_star();
- require_once 'Banco.class.php';
- require_once 'Usuario.class.php';
- $u = new Usuario();
- $u->login($_POST['email'],$_POST['senha']);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement