Ver Mensaje Individual
  #1 (permalink)  
Antiguo 09/01/2010, 11:45
dariones123
 
Fecha de Ingreso: enero-2010
Mensajes: 22
Antigüedad: 14 años, 4 meses
Puntos: 0
Cerrar sesion cuando cierren navegador

estuve viendo algunos manuales en PHP sobre sesiones y obtuve los siguientes scripts:

INDEX.PHP
Código PHP:
<html>
<head>
<title>Autentificación PHP</title>
</head>
<body>
<h1>Autentificación PHP</h1>
<form action="control.php" method="POST">
<table align="center" width="225" cellspacing="2" cellpadding="2" border="0">
<tr>
<td colspan="2" align="center"
<?if ($_GET["errorusuario"]=="si"){?>
bgcolor=red><span style="color:ffffff"><b>Datos incorrectos</b></span>
<?}else{?>
bgcolor=#cccccc>Introduce tu clave de acceso
<?}?></td>
</tr>
<tr>
<td align="right">USER:</td>
<td><input type="Text" name="usuario" size="8" maxlength="50"></td>
</tr>
<tr>
<td align="right">PASSWD:</td>
<td><input type="password" name="contrasena" size="8" maxlength="50"></td>
</tr>
<tr>
<td colspan="2" align="center"><input type="Submit" value="ENTRAR"></td>
</tr>
</table>
</form>
</body>
</html>
CONTROL.PHP
Código PHP:
<?
//vemos si el usuario y contraseña es váildo
if ($_POST["usuario"]=="CLAVE" && $_POST["contrasena"]=="MICONTRASEÑA"){
    
//usuario y contraseña válidos
    //defino una sesion y guardo datos
    
session_start();
    
$_SESSION["autentificado"]= "SI";
    
header ("Location: aplicacion.php");
}else {
    
//si no existe le mando otra vez a la portada
    
header("Location: index.php?errorusuario=si");
}
?>
SEGURIDAD.PHP
Código PHP:
<?
//Inicio la sesión
session_start();

//COMPRUEBA QUE EL USUARIO ESTA AUTENTIFICADO
if ($_SESSION["autentificado"] != "SI") {
    
//si no existe, envio a la página de autentificacion
    
header("Location: index.php");
    
//ademas salgo de este script
    
exit();
}
?>

APLICACION.PHP
Código PHP:
<?include ("seguridad.php");?>
<html>
<head>
<title>Aplicación segura</title>
</head>
<body>
<h1>Si estás aquí es que te has autentificado</h1>
<br>
----
<br>
Aplicación segura
<br>
----
<br>
<br>
<a href="salir.php">Salir</a>
</body>
</html>

SALIR.PHP
Código PHP:
<?
session_start
();
session_destroy();
?>
<html>
<head>
<title>Has salido!!</title>
</head>
<body>
Gracias por tu acceso
<br>
<br>
<a href="index.php">Formulario de autentificación</a>
</body>
</html>

El problema que tengo, y estuve buscando en foros, pero no me resulto nada, es que cuando el usuario cierra la ventana del navegador o cambia de web sin haber apretado en "SALIR", la sesion queda abierta... me prodrian ayudar porfa?


Gracias...