A página está assim:
<?php
session_start();
if (!isset($_SESSION['s_login'])) {
header("Location: senha.php");
exit;
}
?>
<html>
<head>
<title>...</title>
</head>
<body>
<?php
date_default_timezone_set('America/Sao_Paulo');
$script_tz = date_default_timezone_get();
$km = $_POST['km'];
$lc = $_POST['lc'];
$hr = (date('H')).":".date('i').":".date('s');
$dt = date('Y')."-".date('m')."-".date('d');
$ip = $_SESSION['nome_usuario']." ".$_SERVER['HTTP_USER_AGENT']."; IP: ".$_SERVER['REMOTE_ADDR'];
$lt = $_POST['lat'];
$ln = $_POST['lon'];
echo "<font face='arial' color='green' size='150'>";
echo "<br>";
echo "<br>";
include("conexao.php");
conectk("","");
$sql="INSERT INTO carro (tipoauto,km,local,data,hora,ipcad,latitude,longitude,vldesp,vllitro) values ('".$car."',".$km.",'".$lc."','".$dt."','".$hr."','".$ip."','".$lt."','".$ln."',0,0)";
$rs=mysql_query($sql);
if (!$rs)
{ echo '<BR>';
echo mysql_error();
echo '<BR>';
echo '<BR>';
echo $sql;
echo '<BR>';
exit("Error in SQL");}
else
{echo "Cadastrado";}
echo '<br>';
?>
<?php
session_destroy();
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo '<form action="/site/index.html"';
echo "width='65%' style='height:150px;'>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<br>";
echo "<input size='25' style='font-size:100px' type='submit' id='Sair' value='Sair'>";
echo "</form>";
?>
A senha.php está assim:
<?php
session_start();
include("conexao.php");
conectk();
$senha = ( isset($_POST['senha']) ) ? $_POST['senha'] : $_GET['senha'];
$usuario = ( isset($_POST['usuario']) ) ? $_POST['usuario'] : $_GET['usuario'];
$url = 'http://'.$_SERVER['SERVER_NAME'].$_SERVER['PHP_SELF'];
$erro = 0;
$mensagem = '';
$encerra = ( isset($_POST['logout']) ) ? $_POST['logout'] : $_GET['logout'];
if (!isset($_SESSION['s_login']))
{
if($senha)
{
$SQL = "SELECT * FROM numeros WHERE senha = '". $senha . "'";
$result_id = mysql_query($SQL) or die("Erro no banco de dados: ".$SQL);
$total = mysql_num_rows($result_id);
if($total)
{
$dados = mysql_fetch_array($result_id);
$usuario = $dados["usuario"];
$_SESSION['s_login'] = $senha;
$_SESSION['nome_usuario'] = $usuario;
echo "<br>";
echo $_SESSION['nome_usuario'];
echo "<br>";
echo "<br>";
header("Location: cadcarro2.php");
exit;
}
else
{
if ((!$senha))
{
$erro = 1;
}
else
{
$erro = 2;
}
}
}
}
else
{
if ($encerra==1)
{
session_unset();
session_destroy();
$erro = 3;
}
else
{
header("Location: cadcarro2.php");
exit;
}
}
if ($erro!=4)
{
}
?>
<!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 do aluno</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="3" cellspacing="3">
<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 inválida!!!
<?php
} elseif ($erro==3) {
?>
Logout realizado com sucesso!!!
<?php
}
?>
</div>
<BR>
Forneça sua senha para acesso:
<BR>
<form method="post" action="<?php echo $url; ?>"> Senha: <input size="25" name="senha" id="senha"
type="tel"><br>
<br>
<div style="text-align: center;"><input name="Submit"
value="Entrar" type="submit"><input type="button" value="Voltar" onClick="location.href='../';">
</div>
</form>
<form <input size="30"><br>
<BR>
</td>
</tr>
</tbody>
</table>
</div>
</form> </td>
</tr>
</tbody>
</table>
<br>
</body>
</html>
Imagino que eu esteja fazendo algo errado, mas não consigo achar o quê.
O problema é que, frequentemente (mas nem sempre), o $_SESSION['nome_usuario'] está em branco, mas ainda assim ele não pede a senha.
Alguém pode me dar uma luz?