Ver Mensaje Individual
  #1 (permalink)  
Antiguo 31/03/2005, 15:50
-chukie-
 
Fecha de Ingreso: marzo-2005
Mensajes: 3
Antigüedad: 19 años
Puntos: 0
[script] Sistema con claves de un solo uso

Bueno pues yo soy nuevo en este foro pero ya he usado los scripts de la pagina y es por eso que pongo este script que es para crear un sistema con claves de un solo uso
Que es eso ? bueno pues es un sistema que tiene claves que cuando la introduce si esta bien entras y luego si intentas entrar con ella otra vez ya no puedes tienes que introducir otra clave.

[script]

Creas una tabla llamada clave



Código:
CREATE TABLE `clave` (
`id` BIGINT( 7 ) NOT NULL AUTO_INCREMENT ,
`clave` VARCHAR( 12 ) NOT NULL ,
PRIMARY KEY ( `id` ) 
);

creas index.php y escribes lo siguiente:



Código:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Claves</title>
</head>

<body>


<center>
<form action="claves2.php" method="post">
Clave: <input name="clave" type="text" size="12" maxlength="12"><br><br>
<input name="Enviar" type="submit" value="Enviar">
</form>
</center>


</body>
</html>
creas claves2.php y escribes:



Código:
<?php 
$dbh=mysql_connect ("localhost", "usuario", "pass") or die ('I cannot connect to the database because: ' . mysql_error());
mysql_select_db ("tabla");

$_POST["clave"];
$result = mysql_query("SELECT * FROM `claves` WHERE clave ='$clave'");
$row = mysql_fetch_array( $result ); 
if ($row['clave']==$clave)
{
mysql_query("DELETE FROM claves WHERE clave='$clave'");
setcookie("clave", $clave, time()+36000);
echo "<META HTTP-EQUIV='refresh' CONTENT='0; URL=claves3.php'>"; 
} 
else {
echo "Clave incorrecta o ya ha sido utilizada.";
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Claves</title>
</head>

<body>

</body>
</html>

ahora creeas claves3.php y escribes:



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

<body>
<br><br><br>
<?php
if (isset($_COOKIE["clave"]))
{
echo "<center>";
echo "Esto lo puedes ver solo si has ingresado una clave correctamente.";
echo "Recuerda que la clave una vez usada ya no podra ser utilizada otra vez.";
echo "</center>";
echo "Cuando termines click <a href='logout.php'>aqui.</a>";
}
else {
echo "No haz ingresado una clave correcta. <a href='index.php'>Regresar.</a>";
}
?>

</body>
</html>

y por ultimo creas logout.php



Código:
<?php
setcookie("clave");
echo "<META HTTP-EQUIV='refresh' CONTENT='0; URL=index.php'>";
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Documento sin t&iacute;tulo</title>
</head>

<body>

</body>
</html>

recuerda poner al ultimo de la pagina claves3.php el logout porke si no te das logout e intentas entrar te da error