Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/07/2003, 09:41
yamakasiz
 
Fecha de Ingreso: febrero-2002
Mensajes: 139
Antigüedad: 22 años, 2 meses
Puntos: 0
Si lo que quieres es que tus visitantes deban registrarse usa BDD, si lo que quieres es tener una páguina restringida para ti y para tus conocidos te coloco el script entero que uso yo, consta de 4 archivos:

control.php
<?
//vemos si el usuario y contraseña es váildo. Cambia miguel y qwerty por el user y pass que quieras
if ($_POST["usuario"]=="miguel" && $_POST["contrasena"]=="qwerty"){
//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();
}
?>


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


Y en cada página que quieras proteger debes meterle un include a seguridad.php. Ejemplo:

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


Es un poco largo :p
Espero que te sirva.

Un saludo.