Ver Mensaje Individual
  #17 (permalink)  
Antiguo 08/01/2009, 12:22
Avatar de farra
farra
 
Fecha de Ingreso: marzo-2008
Ubicación: Aqui estoy
Mensajes: 574
Antigüedad: 16 años, 2 meses
Puntos: 20
Respuesta: Simple sistem autentificacion ( texto plano)

como hacer un sistema de logueo sin base de datos ni archivos de texto...

facil, crea estos archivos y listo!


login.php:
Código PHP:
<?php 
require("conf.php");

if(isset(
$_POST['user'])){

// asignar valor a la sesion
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];

}

// direccionar si existe sesion
if(($_SESSION['user'] == $user) && ($_SESSION['pass'] == $pass)){
header("location: index.php");
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Ingresar</title>
</head>

<body>
<form id="form1" name="form1" method="post" action="login.php">
  <label>
  Usuario:
  <input type="text" name="user" />
  </label>
  <label> <br />
    Clave:
    <input type="text" name="pass" />
    <br />
  </label>
  <input name="boton" type="submit" value="Ingresar" />
</form>
</body>
</html>
index.php
Código PHP:

<?php require("checkuser.php"); ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Pagina con clave</title>
</head>

<body>
Bienvenido <?php echo $_SESSION['user']; ?> \ <a href="logout.php">Salir</a>
</body>
</html>
checkuser.php:
Código PHP:

<?php
require("conf.php");
if((
$_SESSION['user'] != $user) or ($_SESSION['pass'] != $pass)){
header("Location: login.php");
$_SESSION['pass'] = "";
$_SESSION['user'] = "";
}
?>

conf.php
Código PHP:
<?php 
$user
="admin";
$pass="admin";
if (!isset(
$_SESSION)) {
  
session_start();
}
?>

logout.php
Código PHP:
<?php
if (!isset($_SESSION)) {
  
session_start();
}

$_SESSION['user'] = "";
$_SESSION['pass'] = "";
unset(
$_SESSION['user']);
unset(
$_SESSION['pass']);

header("Location: index.php");
exit;
?>

asi de facil...

y cualquier pagina adicional que quieras crear la creas nomas y arriba mismo de todo tenes que poner <?php require("checkuser.php"); ?> y listo...

y para cambiar tu nombre de usuario y contraseña solo tenes que modificar el archivo config.php
__________________
Firma:
Es mas dificil para el mono entender que el hombre desciende de el....

PD: Siempre doy karma al que me da una buena respuesta... ;0)

Última edición por farra; 08/01/2009 a las 13:36 Razón: cambiar config por conf... coreccion de error