Mi pregunta es la siguiente: tengo un formulario con campos usuario y password; al enviarlos a la pagina login.php me checa los valores y me inicia una session, pero el problema esta que cuando paso a la pagina1.php donde voy a tener mi aplicacion segura, pues, ya no me deja entrar porque vuelve hacer una comprobacion de registrado = si y ya no me deja, pues ,se pierde la session
aqui esta el codigo:
index.php
Código PHP:
<html>
<head>
<title>Formulario de Prueba</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<style type="text/css">
<!--
.boton { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 9pt; color: #FFFFF0; background-color: #000099; border-color: #000000 ; border-top-width: 1pix; border-right-width: 1pix; border-bottom-width: 1pix; border-left-width: 1pix}
.label { font-size: 10pt; color: #000099; background-color: #EFEFEF; font-family: Verdana, Arial, Helvetica, sans-serif; border: 1pix #000000 solid; border-color: #000000 solid; font-weight: normal}
-->
</style>
<?php
session_start();
if(!isset($_SESSION['registro']))
{
Formulario();
}
else
echo"<html>\n<head>\n<script language=\"JavaScript\">\nalert('Ya has iniciado sesion');</script>\n</head>\n</html>";
?>
<body>
<h1 align="center">Iniciar Sesion</h1>
<?php
function formulario()
{?>
<form action="login.php" method="post">
<table width="246" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF" bgcolor="#0000CC">
<tr>
<td>
<?php
if ($_GET["error"]=="si")
{?>
<bgcolor=red><span style="color:ffffff"><b>Datos incorrectos</b></span>
<?}else{?>
<div align="center"><font color="#FFFFFF" face="Verdana"><strong>Formulario:Prueba</strong></font></div>
<?}?>
</td>
</tr>
</table>
<div align="center"></div>
<table width="246" height="100" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#EFEFEF">
<tr>
<td width="256"><p align="center"><font color="#000066" size="2" face="Verdana"><strong>Usuario </strong></font>
<input name="usuario" type="text" class="label" id="usuario" size="15" maxlength="15">
</p>
<p align="center"><font color="#000066" size="2" face="Verdana"><strong>Password</strong></font>
<input name="password" type="password" class="label" id="password2" size="15" maxlength="15">
</p>
</td>
</tr>
</table>
<div align="center">
<input name="enviar" type="submit" id="enviar" value="Enviar" class="boton">
<input name="borrar" type="reset" id="borrar" value="Borrar" class="boton">
</div>
</form>
<?php
}
?>
</body>
</html>
Código PHP:
<?php
if(empty($_POST["usuario"]) || empty($_POST["password"]))
{
header("Location: index.php?error=si");
exit();
}
elseif($_POST["usuario"]== "user" && $_POST["password"] == "user")
{
session_start();
$_SESSION['registro']="si";
echo 'Registrado:*';
echo $_SESSION['registro'];
echo "\nsesion ID= \n";
echo session_id();
echo "\nsesion name= \n";
echo session_name();
echo " \n <a href='pagina1.php'>Pagina Segura </a>";
}
else
header("Location: index.php?error=si");
?>
Código PHP:
<?php
session_start();
if(!isset($_SESSION['registro']))
{
header("Location: index.php?error=si");
}
else
echo"<html>\n<head>\n<script language=\"JavaScript\">\nalert('Pagina Segura');</script>\n</head>\n</html>";
echo "<h1>Cualquier Aplicacion</h1>";
?>