Tema: setcookie
Ver Mensaje Individual
  #6 (permalink)  
Antiguo 21/02/2005, 09:17
stefmonl
 
Fecha de Ingreso: abril-2004
Mensajes: 69
Antigüedad: 20 años
Puntos: 0
aqui esta el codigo entero

<?
include("func/vars.inc.php");
include("func/functions.inc.php");
include("func/data.inc.php");
?>
<html>
<head>
<title>Identificación de usuario en las areas restringidas</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link rel="stylesheet" type="text/css" href="../Estilos/Estilos/estiloGDT.css">
<link rel="stylesheet" type="text/css" href="../Estilos/estiloGDT.css">
<link rel="stylesheet" type="text/css" href="../Estilos/estiloGDT.css">
</head>

<body>
<?

//Aquí conexión o include() de archivo de conexion con base de datos.
include("conexion_bd.php");

function quitar($mensaje)
{
$mensaje = str_replace("<","<",$mensaje);
$mensaje = str_replace(">",">",$mensaje);
$mensaje = str_replace('\\\\','\'',$mensaje);
$mensaje = str_replace("\'","'",$mensaje);
$mensaje = str_replace("\"",'"',$mensaje);
return $mensaje;
}

if(trim($HTTP_POST_VARS["usuario"]) !="" && trim($HTTP_POST_VARS["passwd"]) !="")
{
$nickN = quitar($HTTP_POST_VARS["usuario"]);
$passN = quitar($HTTP_POST_VARS["passwd"]);

//$result = mysql_query("SELECT passwd FROM usuarios WHERE usuario='$nickN'");
$conditions = "WHERE usuario='$nickN'";
$result = db_query("usuarios","passwd",$conditions);


if($row = db_fetch_array($result))
{
if($row["passwd"] == $passN)
{
//90 dias dura la cookie = (60*60*24*90) = 7776000 segundos
setcookie("usNick", $nickN, time()+7776000);
setcookie("usPass", $passN, time()+7776000);
//Ingreso exitoso, ahora sera dirigido a la pagina restringida.

?>
<SCRIPT LANGUAGE="javascript">
alert ("Usuario con acceso a esta area");
location.href="login.php";
</SCRIPT>
<?

}
else
{
?>
<script language="javascript">
alert ("Password incorrecto");
</script>
<?
}
}
else
{
?>
<script language="javascript">
alert ("Usuario no existente en la base de datos");
</script>
<?
}
mysql_free_result($result);
}
else
{
?>
<script language="javascript">
alert ("Debe especificar un nombre de usuario y password");
</script>
<?
}
//mysql_close();
db_disconnect();
?>
<div align="center">
<table border="0" cellpadding="4" width="99" cellspacing="4">
<tr>
<td width="37"><a href="http://correo/ai" target="_top"><img border="0" src="../Images/IcoGDT.gif" alt="Página principal" width="50" height="50"></a></td>
<td width="66"><a href="javascript:history.back();" target="_top"><img border="0" src="http://correo/ai/Images/icoflecha.jpg" alt="Volver a la página anterior" width="50" height="50"></a></td>
</tr>
</table>
</div>
</body>
</html>