<?php
require('configurazioni/config.php');
if(isset($_POST['registra']))
{
$user =(isset($_POST['user'])) ? trim($_POST['user']) : '';
$pass =(isset($_POST['pass'])) ? trim($_POST['pass']) : '';
$mail =(isset($_POST['mail'])) ? trim($_POST['mail']) : '';
$nome =(isset($_POST['nome'])) ? trim($_POST['nome']) : '';
$cognome = (isset($_POST['cognome'])) ? trim($_POST['cognome']) : '';
$lvl = "0";
$desc_lvl = "Utente";
if (!get_magic_quotes_gpc()) {
$user = addslashes($user);
$pass = addslashes($pass);
$mail = addslashes($mail);
$nome = addslashes($nome);
$cognome = addslashes($cognome);
$lvl = "0";
$desc_lvl = "Utente";
}
if(strlen($user) < 4 || strlen($user) > 12)
die('Nome Utente troppo corto, o troppo lungo');
elseif(strlen($pass) < 4 || strlen($pass) > 12)
die('Password troppo corta, o troppo lunga');
elseif(!preg_match("/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,6}$/i", $mail))
die('Email non valida');
elseif(mysqli_num_rows(mysqli_query($dbh, "SELECT user FROM utenti WHERE user = '$user' LIMIT 1")) == 1)
die('Nome Utente non disponibile');
elseif(mysqli_num_rows(mysqli_query($dbh, "SELECT mail FROM utenti WHERE mail = '$mail' LIMIT 1")) == 1)
die('Questo indirizzo email risulta già registrato ad un altro utente');
elseif(strlen($nome) < 4 || strlen($nome) > 20)
die('Nome troppo corto, o troppo lungo');
elseif(strlen($cognome) < 3 || strlen($cognome) > 20)
die('Cognome troppo corto, o troppo lungo');
else
{
$pass = base64_encode($pass);
$strSQL = "INSERT INTO utenti (user,pass,mail,lvl,nome,cognome,desc_lvl)";
$strSQL .= "VALUES('$user', '$pass', '$mail', '$lvl', '$nome', '$cognome', '$desc_lvl')";
mysqli_query($dbh, $strSQL) OR die("Errore 003, contattare l'amministratore ".mysqli_error());
session_start();
$_SESSION['user'] = $user;
utente ad una pagina di conferma della registrazione
header('Location: index.php');
exit;
}
}
?>
<form action="" method="post">
<table width="100" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>User Name</td>
<td><input name="user" type="text" id="user" value="Nome Utente" onfocus="if(this.value=='Nome Utente') this.value='';" /></td>
</tr>
<tr>
<td>Nome: *</td>
<td><input name="nome" type="text" id="nome" value="Nome Reale" onfocus="if(this.value=='Nome Reale') this.value='';" /></td>
</tr>
<tr>
<td>Cognome: *</td>
<td><input name="cognome" type="text" id="cognome" value="Cognome Reale" onfocus="if(this.value=='Cognome Reale') this.value='';" /></td>
</tr>
<tr>
<td>Password: *</td>
<td><input name="pass" type="password" id="pass" value="Password" onfocus="if(this.value=='Password') this.value='';" /></td>
</tr>
<tr>
<td>Email:</td>
<td><input name="mail" type="text" id="mail" value="Em@il" onfocus="if(this.value=='Em@il') this.value='';" /></td>
</tr>
<tr>
<td><input name="registra" type="submit" value="Registrati" /></td>
<td> </td>
</tr>
</table>
</form>