Ver Mensaje Individual
  #5 (permalink)  
Antiguo 26/02/2003, 22:07
Connie
 
Fecha de Ingreso: febrero-2003
Mensajes: 3
Antigüedad: 21 años, 2 meses
Puntos: 0
Hice una tabla en la base de datos
Cree los docmentos registrar, ingresar, y login

registrar:>>

<html>
<head>
<?php

//AQUI CONEXION CON LA BASE DE DATOS

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

if(trim($HTTP_POST_VARS["nick"]) != "" && trim($HTTP_POST_VARS["email"]) != "")
{
$sql = "SELECT id FROM usuarios WHERE nick='".quitar($HTTP_POST_VARS["nick"])."'";
$result = mysql_query($sql);
if($row = mysql_fetch_array($result))
{
echo "Error, nick escogido por otro usuario";
}
else
{
$sql = "INSERT INTO usuarios (nick,password,nombre,email) VALUES (";
$sql .= "'".quitar($HTTP_POST_VARS["nick"])."'";
$sql .= ",'".quitar($HTTP_POST_VARS["password"])."'";
$sql .= ",'".quitar($HTTP_POST_VARS["nombre"])."'";
$sql .= ",'".quitar($HTTP_POST_VARS["email"])."'";
$sql .= ")";
mysql_query($sql);
echo "Registro exitoso!";
}
mysql_free_result($result);
}
else
{
echo "Debe llenar como minimo los campos de email y password";
}
mysql_close();
?>

<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html>


--------------------------------------------------------
INGRESAR>>

<html>
<head>
<?php

//AQUÍ CONEXION CON LA BASE DE DATOS

function quitar($mensaje)
{
$mensaje = str_replace("<","&lt;",$mensaje);
$mensaje = str_replace(">","&gt;",$mensaje);
$mensaje = str_replace("\'","'",$mensaje);
$mensaje = str_replace('\"',"&quot;",$mensaje);
$mensaje = str_replace("\\\\","&#92",$mensaje);
return $mensaje;
}

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

$result = mysql_query("SELECT password FROM usuarios WHERE nick='$nickN'");
if($row = mysql_fetch_array($result))
{
if($row["password"] == $passN)
{
//90 dias dura la cookie
setcookie("usNick",$nickN,time()+7776000);
setcookie("usPass",$passN,time()+7776000);
?>
Ingreso exitoso, ahora sera dirigido a la pagina principal.
<SCRIPT LANGUAGE="javascript">
location.href = "index.php";
</SCRIPT>
<?
}
else
{
echo "Password incorrecto";
}
}
else
{
echo "Usuario no existente en la base de datos";
}
mysql_free_result($result);
}
else
{
echo "Debe especificar un nick y password";
}
mysql_close();
?>

<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>

</body>
</html>


-------------------------------------------------------------

LOGIN>>

<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<?php
$loginCorrecto = false;
$idUsuarioL;
$nickUsuarioL;
$emailUsuarioL;
$nombreUsuarioL;

if(isset($HTTP_COOKIE_VARS["usNick"]) && isset($HTTP_COOKIE_VARS["usPass"]))
{
$result = mysql_query("SELECT * FROM usuarios WHERE nick='".$HTTP_COOKIE_VARS["usNick"]."' AND password='".$HTTP_COOKIE_VARS["usPass"]."'");

if($row = mysql_fetch_array($result))
{
setcookie("usNick",$HTTP_COOKIE_VARS["usNick"],time()+7776000);
setcookie("usPass",$HTTP_COOKIE_VARS["usPass"],time()+7776000);
$loginCorrecto = true;
$idUsuarioL = $row["id"];
$nickUsuarioL = $row["nick"];
$emailUsuarioL = $row["email"];
$nombreUsuarioL = $row["nombre"];
}
else
{
//Destruimos las cookies.
setcookie("usNick","x",time()-3600);
setcookie("usPass","x",time()-3600);
}
mysql_free_result($result);
}
?>

</body>
</html>


--------------------------------------------------------------

lUEGO CREE LOS FORMULARIOS CORRESPONDIENTES:

INGRESAR:>>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<FORM ACTION="ingresar.php" METHOD="post">
Nick : <INPUT TYPE="text" NAME="nick" SIZE=20 MAXLENGTH=20>
<BR>
Password: <INPUT TYPE="password" NAME="password" SIZE=28 MAXLENGTH=20>
<BR>
<INPUT TYPE="submit" CLASS="boton" VALUE="Ingresar">
</FORM>

</body>
</html>



----------------------------------------------------------------------

REGISTRARSE>>>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>Documento sin t&iacute;tulo</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>
<FORM ACTION="http://usuarios.lycos.es/ambarhdn/registrar.php" METHOD="post">
Nick : <INPUT TYPE="text" NAME="nick" SIZE=20 MAXLENGTH=20>
<BR>
Email: <INPUT TYPE="text" NAME="email" SIZE=28 MAXLENGTH=100>
<BR>
Password: <INPUT TYPE="password" NAME="password" SIZE=28 MAXLENGTH=20>
<BR>
Nombre: <INPUT TYPE="text" NAME="nombre" SIZE=28 MAXLENGTH=255>
<BR>
<INPUT TYPE="submit" CLASS="boton" VALUE="Registrar">
</FORM>


</body>
</html>





------------------------------------------------

Hago la conexion con la base de datos donde dice "AQUÍ CONEXION CON LA BASE DE DATOS" , subí todo, pero me registra los usuarios, y a la hora de ingresar no me los reconoce, diciendome q' son inexistentes
¿q' puedo hacer?