0% found this document useful (0 votes)
50 views4 pages

Code en PHP para Registrarse

This PHP code handles user registration. It checks if a user's nickname already exists in a database and either registers the new user or returns an error. On successful registration, it displays the user's registered details and a link to return to the main page. Otherwise, it returns errors if required fields are missing or invalid and links back to the registration page.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views4 pages

Code en PHP para Registrarse

This PHP code handles user registration. It checks if a user's nickname already exists in a database and either registers the new user or returns an error. On successful registration, it displays the user's registered details and a link to return to the main page. Otherwise, it returns errors if required fields are missing or invalid and links back to the registration page.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

<?

php
session_start();
//header("Cache-Control", "no-cache, no-store, must-revalidate");
$nombre = $grupo = $nickname = $clave = "";
if (isset($_POST['Nnombre']) && isset($_POST["Ggrupo"]) &&
isset($_POST["Nnickname"]) && isset($_POST['Cclave']) &&
$_SESSION['checando']="uno") {
global $nombre, $nickname,$clave, $grupo;
$nombre = test_input($_POST['Nnombre']);
$grupo = test_input($_POST['Ggrupo']);
$nickname = test_input($_POST['Nnickname']);
$clave = test_input($_POST['Cclave']);
GrabandoDatos();
//Registrandose();
}
else {
Registrandose();
}

function test_input($data) {
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}

function Registrandose(){
$_SESSION['checando']="uno";
echo '<!DOCTYPE HTML>';
echo '<html>';
echo '<head>';
echo '<meta charset="UTF-8">';
estilos();
echo '<title>User Login Form</title>';
echo '<style>
table, td, th { border: 0px solid black; }
table { border-collapse: collapse; width: 50%; }
th { height: 50px; }
</style>';
echo '</head>';
echo '<body BGCOLOR="#C8C8C8">';
echo '<center>';
if ($_SESSION['UsuarioYaExiste'] == "verdad"){
echo '<H1>!!! El Nickname que habías elegido ya existe. !!!. </H1>';
$_SESSION['UsuarioYaExiste'] = "falso";
}
else if ($_SESSION['UsuarioYaExiste'] == "Faltandatos"){
echo '<H1>!!! Anota tus datos correctamente !!!. </H1>';
$_SESSION['UsuarioYaExiste'] = "falso";
}
//else if ($_SESSION['UsuarioYaExiste'] == "Registrado"){
// echo '<H1>!!! Listo. Ya estas registrado !!!. </H1>';
// $_SESSION['UsuarioYaExiste'] = "falso";
//}
else
echo '<H1>!!! Bienvenido !!! </H1>';
echo '<table>';

echo '<TR BGCOLOR="#C8C8C8"><TD>';


//echo '<H1>Nuevo Usuario? <BR><center>Registrate</center></H1><H2>';
echo '<H1><center>Registrate</center></H1><H2>';
echo '<center>';
echo '<form action="registrate.php" method="POST">';
echo '<STRONG>Nombre:</STRONG>(20 a 40 caracteres)<BR>';
echo '<input style="font-size:48px" type="text" autocomplete="off"
name="Nnombre" value="" class="textform"><BR>';
echo '<STRONG>Grupo:(4 caracteres ejemplo M509) </STRONG><BR>';
echo '<input style="font-size:48px" type="text" autocomplete="off"
name="Ggrupo" value="" class="textform"><BR>';
echo '<STRONG>Nickname:(8 a 12 caracteres) </STRONG><BR>';
echo '<input style="font-size:48px" type="text" autocomplete="off"
name="Nnickname" value="" class="textform"><BR>';
echo '<STRONG>Clave: (6 a 8 caracteres) </STRONG><BR>';
echo '<input style="font-size:48px" type="text" autocomplete="off"
name="Cclave" value="" class="textform"><BR>';
//echo '<input style="font-size:48px" type="submit" name="submit"
value="Registrar" />';
//echo '<center>';
echo '<button type="submit" style="border: 0; background:
transparent" name="submit" value="Iniciar"><img src="/imagenes/
Submit.png" width="100" height="100" alt="SomeAlternateText"></
button>';
echo '</center>';
echo '</form>';
echo '</H2></center>';
echo '</TD>';
echo '</TR>';
echo '</table>';

echo '</body>';
echo '</html>';
}

function GrabandoDatos(){
echo '<html>';
echo '<head>';
echo '<meta charset="UTF-8">';
echo '</head>';
echo '<body BGCOLOR="#C8C8C8">';

$confirmacion = true;
$file = fopen("RegistroUsuarios.txt","r");

while(! feof($file)){
$records = fgetcsv($file);
// echo "{$records[0]} {$records[1]}<br />";
if ($_POST['Nnickname'] == $records[0] && $_POST['Nnickname']!=""){
$confirmacion = false;
echo '<center>';
echo "<br><br><H1>Nickname ya existe. <br><br><br><br>";
echo '<a href="registrate.php">Ir a página de registro</a> <br>';
echo "</H1>";
//echo "Nickname ya existe. <BR>";
$_SESSION['UsuarioYaExiste'] = "verdad";

}
}

fclose($file);

if ($confirmacion){
$confirmacion = false;
$_SESSION['checando'] = "cero";

//header('Location: registrate.php');

global $nombre, $nickname,$clave, $grupo;


$file = fopen("RegistroUsuarios.txt","a");
$a1 = $nickname;
$a2 = $nombre;
$a3 = $clave;
$a4 = $grupo;
if (strlen($a1) >= 8 && strlen($a1) <= 12 &&
strlen($a2) >= 20 &&
strlen($a3) >= 6 && strlen($a3) <= 8 &&
strlen($a4) >= 4){
$todos = array($a1, $a2, $a3, $a4);
fputcsv($file, $todos, ',');
//$_SESSION['UsuarioYaExiste'] = "Registrado";
//global $nombre, $nickname,$clave, $grupo;
echo '<center>';
echo "<br><H1>Los datos que ingresaste son: <br>";
echo "Nombre: ".$nombre."<br>";
echo "Grupo: ".$grupo."<br>";
echo "Usuario: ".$nickname."<br>";
echo "Password: ".$clave."<br>";
echo "<br>Recuerda anotar tu USUARIO y el PASSWORD <br>";
echo "porque los necesitarás mas adelante.<br><br><br>";
echo '<a href="index.php">Ir a página principal</a>';
echo '<p> <a href="index.php"><img src="/imagenes/smiley.gif"
alt="!" width="42" height="42" border="0"></a></p>';
echo "</H1>";
echo '</center>';
unset($_POST['Nnombre']);
unset($_POST['Ggrupo']);
unset($_POST['Nnickname']);
unset($_POST['Cclave']);
}
else{

//echo "QUE NO ENTIENDES ??? Error en los datos que


ingresaste.<BR><BR>";
echo '<center>';
echo "<br><br><br><br><H1>Hay un error en los datos que ingresaste.
<br><br><br><br><br><br>";
echo '<a href="registrate.php">Ir a página de registro</a> <br>';
echo "</H1>";
$_SESSION['UsuarioYaExiste'] = "Faltandatos";
//echo '<a href="registrate.php">Ir a página de registro</a>';
}
fclose($file);

//echo '<a href="registrate.php">Ir a página de registro</a>';


//header('Location: registrate.php');
}
else{
$_SESSION['checando'] = "cero";
//echo "QUE NO ENTIENDES ??? Usuario ya existe. <BR><BR>";
//header('Location: registrate.php');
}

//echo '<a href="registrate.php">Ir a página de registro</a>';


echo '</body>';
echo '</html>';
}

function estilos(){
echo '<style>
h1 { font-size: 50; }
h2 { font-size: 38px; }
h3 { font-size: 26px; }
p { font-size: 10px; }
</style>';
}
?>

You might also like