Ver Mensaje Individual
  #2 (permalink)  
Antiguo 26/12/2002, 09:58
Avatar de chalito
chalito
 
Fecha de Ingreso: diciembre-2002
Ubicación: Santiago, chile
Mensajes: 221
Antigüedad: 21 años, 4 meses
Puntos: 0
Hola
solo pongo el mismo codigo coloreado, es mas facil de leer

Código PHP:
<html>
<head>
<title>Autentificación en 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">USUARIO:</td>
<td><input type="Text" name="usuario" size="8" maxlength="50"></td>
</tr>
<tr>
<td align="right">PASSWORD:</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----------------------------------

<?
//vemos si el usuario y contraseña es váildo
if ($_POST["usuario"]=="downwarez" && $_POST["contrasena"]=="colaboracion"){
//usuario y contraseña válidos
//defino una sesion y guardo datos
session_start();
session_register("autentificado");
$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---------------------------------

<?
//TOMO VARIABLES DE SESION SOBRE LA AUTENTIFICACION
session_register("autentificado");
//COMPRUEBA QUE EL USUARIO ESTA AUTENTIFICADO
if ($autentificado != "SI") {
//si no existe, envio a la página de autentificacion
header("Location: index.php");
//ademas salgo de este script
exit();
}
?>

-----------------------------SALIR.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>