<?php
session_start();
$usuario = ( isset($_POST['usuario']) ) ? $_POST['usuario'] : $_GET['usuario'];
$senha = ( isset($_POST['senha']) ) ? $_POST['senha'] : $_GET['senha'];
$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$erro = 0;
$mensagem = '';
$log = "xxx";
$pas = "xxx";
$encerra = ( isset($_POST['logout']) ) ? $_POST['logout'] : $_GET['logout'];
if (!isset($_SESSION['s_login'])) {
if (($usuario == $log) && ($senha == $pas)) {
$_SESSION['s_login'] = $usuario;
} else {
if ((!$usuario) || (!$senha)) {
$erro = 1;
} else {
$erro = 2;
}
}
} else {
if ($encerra==1) {
session_unset();
session_destroy();
$erro = 3;
}
}
if ($erro!=0) {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=ISO-8859-1"
http-equiv="content-type">
<title>Login para a área restrita</title>
<style>
#Centralizar {
position: absolute;
width: auto;
height: auto;
left: 30%;
top:30%;
margin-left: -250px;
margin-top: -68px;
}
</style>
</head>
<body>
<div id="Centralizar">
<table style="text-align: left; width: 800px; height: 236px;" border="1"
cellpadding="2" cellspacing="2">
<tbody>
<tr>
<td style="width: 55%; text-align: center;"><img
style="width: 228px; height: 228px;" alt="" src="login.png"></td>
<td style="width: 75%;">
<div style="text-align: center;">
<?php
if ($erro==2) {
?>
Senha ou usuário inválido!!!
<?php
} elseif ($erro==3) {
?>
Logout realizado com sucesso!!!
<?php
}
?>
</div>
<form method="post" action="<?php echo $url; ?>"> Usuário:
<input size="60" name="usuario" id="usuario"><br>
<br>
Senha: <input size="50" name="senha" id="senha"
type="password"><br>
<br>
<div style="text-align: center;"><input name="Submit"
value="Entrar" type="submit"><input type="button" value="Voltar" onClick="location.href='../';">
</div>
</form>
</td>
</tr>
</tbody>
</table>
</div>
<br>
</body>
</html>
<?php
}
?>
Estou precisando fazer uma nova aplicação, com a mesma ideia, mas com duas modificações:
1) tirar a exigência de usuário; basta a senha;
2) conferir a senha em uma tabela de uma base de dados MySQL: neste que postei acima, a senha é predefinida. Mas no que quero fazer agora eu quero que ele verifique se a senha digitada consta na tabela MySQL; se constar, ele autoriza a utilização do PHP, passando os dados do usuário constantes da tabela MySQL; se não constar, ele dá a informação de "senha errada".
Alguém poderia me ajudar a fazer isso?