Arquivo index.php
<?php
include ("cabecalho.php");
?>
<?php if(isset($_GET['login']) && $_GET['login']==0){ ?>
<p class="alert-success">Logado com sucesso!</p>
<?php } ?>
<?php if(isset($_GET['login']) && $_GET['login']==1){ ?>
<p class="alert-danger">Usuário ou senha inválida!</p>
<?php } ?>
<h2>Login</h2>
<form action="login.php" method="POST">
<table class="table">
<tr>
<td>Email</td>
<td><input class="form-control" type="text" name="email"></td>
</tr>
<tr>
<td>Senha</td>
<td><input class="form-control" type="password" name="senha"></td>
</tr>
<tr>
<td><button class="btn btn-primary">Login</button></td>
</tr>
</table>
</form>
<?php
include ("rodape.php");
?>
Arquivo banco-usuario.php
<?php
function buscaUsuario($email, $senha){
$senhaMd5 = md5($senha);
$query = "select * from usuarios where email='{$email}' and senha='{$senhaMd5}'";
$resultado = mysql_query($query);
$usuario = mysql_fecth_assoc($resultado);
return $usuario;
}
?>
Arquivo login.php
<?php
include("conecta.php");
include("banco-usuario.php");
$email = $_POST['email'];
$senha= $_POST['senha'];
$usuario = buscaUsuario($email, $senha);
if($usuario == null){
header("Location: index.php?login=0");
}else{
header("Location: index.php?login=1");
}
die();
?>