0
I immediately in my session, created a logout.php page to destroy the session. So far so good I can scroll down but when I click the back button of the browser I log back in. As I destroy the session?
logout.php
?>
<script>alert("Logout efetuado com sucesso");
window.location="http://dominio.com/area/login.php";
</script>
<?php
//header("Location:http://dominio.com/area/index.php"); exit; // Redireciona o visitante
?>
php access where valid my session
$usuario = mysql_real_escape_string($_POST['login']);
$senha = mysql_real_escape_string($_POST['senha']);
// Validação do usuário/senha digitados
$sql = "SELECT `id_user`, `nome`, `nivel`,`id_franquia` FROM `usuario1` WHERE (`nome` = '".$usuario ."') AND (`senha` = '". $senha ."') LIMIT 1 ";
$query = mysql_query($sql);
if (mysql_num_rows($query) != 1) {
// Mensagem de erro quando os dados são inválidos e/ou o usuário não foi encontrado
?> <script>alert("Login inválido! Tente novamente");
window.location="http://dominio.com/area/login.php";
</script><?php
//header("Location:http://dominio.com/area/login.php");
} else {
// Salva os dados encontados na variável $resultado
$resultado = mysql_fetch_assoc($query);
// Se a sessão não existir, inicia uma
if (!isset($_SESSION)) session_start();
// Salva os dados encontrados na sessão
$_SESSION['UsuarioId'] = $resultado['id_user'];
$_SESSION['UsuarioNome'] = $resultado['nome'];
$_SESSION['UsuarioNivel'] = $resultado['nivel'];
$_SESSION['UsuarioFranquia'] = $resultado['id_franquia'];
if($_SESSION['UsuarioNivel'] ==1){
header("Location:http://dominio.com/area/admin/admin.php");
}else if($_SESSION['UsuarioNivel'] ==2){
header("Location:http://dominio.com/area/editor/editor.php");
}else if($_SESSION['UsuarioNivel'] ==3){
header("Location:http://dominio.com/area/usuario/usuario.php");
}
page that I am directed
php editor.
<?php
if (!isset($_SESSION))
session_cache_expire(10);
session_start();
$nivel_necessario = 2;
// Verifica se não há a variável da sessão que identifica o usuário
if (!isset($_SESSION['UsuarioId']) && ($_SESSION['UsuarioNivel'] !=$nivel_necessario)) {
// Destrói a sessão por segurança
session_destroy();
// Redireciona o visitante de volta pro login
header("Location:http://dominio.com/area/login.php"); exit;
}
$logado = $_SESSION['UsuarioNome'];
?>
Dude, that’s a lot to want code ready. Just google it and you’ll find it in English!
– Douglas Bernardino
This question seems to be out of date because it is a question that could be solved with a quick google search, having no utility to help future users
– RodrigoBorth
I’m voting to close
– RodrigoBorth
why do you have an Else without having an if? how do you check whether you are logged in or not? post all the codes of the pages involved in the process
– RodrigoBorth
added the pages I use
– José Carlos
this is probably because of the return, when you return a page in the browser it probably asks to resend the form data you had sent when you visited that page, as your browser has this data saved it resends creating thus a new session, if you go to the page, manually without using the back button probably the session will not be started
– RodrigoBorth
tested on firefox and Chrome and still redirected me to page, already in IE the session really was destroyed
– José Carlos
I left it open because the question seems normal after editing.
– Jorge B.