codice:
<?
include 'db.php';
// Define post fields into simple variables
$nome = $_POST['nome'];
$cognome = $_POST['cognome'];
$username = $_POST['username'];
$email = $_POST['email'];
$indirizzo = $_POST['indirizzo'];
$citta = $_POST['citta'];
$stato = $_POST['stato'];
$giorno = $_POST['giorno'];
$mese = $_POST['mese'];
$anno = $_POST['anno'];
$peso = $_POST['peso'];
$altezza = $_POST['altezza'];
$capelli = $_POST['capelli'];
$occhi = $_POST['occhi'];
$sesso = $_POST['sesso'];
/* Lets strip some slashes in case the user entered
any escaped characters. */
$nome = stripslashes($nome);
$cognome = stripslashes($cognome);
$username = stripslashes($username);
$email = stripslashes($email);
$indirizzo = stripslashes($indirizzo);
$citta = stripslashes($citta);
$stato = stripslashes($stato);
$giorno = stripslashes($giorno);
$mese = stripslashes($mese);
$anno = stripslashes($anno);
$peso = stripslashes($peso);
$altezza = stripslashes($altezza);
$capelli = stripslashes($capelli);
$occhi = stripslashes($occhi);
$sesso = stripslashes($sesso);
/* Do some error checking on the form posted fields */
if((!$nome) || (!$cognome) || (!$username) || (!$email) || (!$indirizzo) || (!$citta) || (!$stato) || (!$giorno) || (!$mese) || (!$anno) || (!$peso) || (!$altezza) || (!$capelli) || (!$occhi) || (!$sesso)){
echo 'I campi non sono corretti!
';
if(!$nome){
echo "Inserisci il nome.
";
}
if(!$cognome){
echo "Inserisci il cognome.
";
}
if(!$username){
echo "Inserisci un username.
";
}
if(!$email){
echo "Inserisci un email valida.
";
}
if(!$indirizzo){
echo "Inserisci l'indirizzo.
";
}
if(!$citta){
echo "Inserisci la tua città.
";
}
if(!$stato){
echo "Inserisci lo stato.
";
}
if(!$giorno){
echo "Inserisci il giorno.
";
}
if(!$mese){
echo "Inserisci il mese.
";
}
if(!$anno){
echo "Inserisci l'anno.
";
}
if(!$peso){
echo "Inserisci il tuo peso.
";
}
if(!$altezza){
echo "Inserisci la tua altezza.
";
}
if(!$capelli){
echo "Inserisci il colore dei capelli.
";
}
if(!$ochhi){
echo "Inserisci il colore degli occhi.
";
}
if(!$sesso){
echo "Inserisci il tuo sesso.
";
}
include 'join_form.php'; // Show the form again!
/* End the error checking and if everything is ok, we'll move on to
creating the user account */
exit(); // if the error checking has failed, we'll exit the script!
}
/* Let's do some checking and ensure that the user's email address or username
does not exist in the database */
$sql_email_check = mysql_query("SELECT email FROM utenti WHERE email='$email'");
$sql_username_check = mysql_query("SELECT username FROM utenti WHERE utenti='$username'");
$email_check = mysql_num_rows($sql_email_check);
$username_check = @mysql_num_rows($sql_username_check);
if(($email_check > 0) || ($username_check > 0)){
echo "Errore nella compilazione:
";
if($email_check > 0){
echo "[b]Quest'email è stata già registrata da un'altro utente.!
";
unset($email);
}
if($username_check > 0){
echo "Username già in uso da un'altro utente!
";
unset($username);
}
include 'index.htm'; // Show the form again!
exit(); // exit the script so that we do not create this account!
}
/* Everything has passed both error checks that we have done.
It's time to create the account! */
/* Random Password generator.
http://www.phpfreaks.com/quickcode/R...nerator/56.php
We'll generate a random password for the
user and encrypt it, email it and then enter it into the db.
*/
function makeRandomPassword() {
$salt = "abchefghjkmnpqrstuvwxyz0123456789";
srand((double)microtime()*1000000);
$i = 0;
while ($i <= 7) {
$num = rand() % 33;
$tmp = substr($salt, $num, 1);
$pass = $pass . $tmp;
$i++;
}
return $pass;
}
$random_password = makeRandomPassword();
$db_password = md5($random_password);
// Enter info into the Database.
$info2 = htmlspecialchars($info);
$sql = mysql_query("INSERT INTO utenti (nome, cognome, username, email, indirizzo, citta, stato, giorno, mese, anno, peso, altezza, capelli, occhi, sesso, signup_date, decrypted_password)
VALUES('$nome', '$cognome', '$username', '$email', '$indirizzo', '$citta', '$stato', '$giorno', '$mese', '$anno', '$peso', '$altezza', '$capelli', '$occhi', '$sesso', '$signup_date', '$decrypted_password', '$db_password', '$info2', now(), '$random_password')") or die (mysql_error());
if(!$sql){
echo 'Errore nel creare il tuo account. Contatta il webmaster.';
} else {
$userid = mysql_insert_id();
$activatepath = "activate.php?id=$userid&code=$db_password";
// Let's mail the user!
$subject = "Messaggio da: $sitename";
$message = "Caro $nome $cognome,
Sei stato appena registrato su $sitepath !
Per attivare l'account, clicca qui: $sitepath$activatepath
Dopo l'attivazione, inserisci questi dati:
Username: $username
Password: $random_password
Conserva Username e Password per un login futuro.
Grazie!
Webmaster, $sitename
Questa è un email automatica, non rispondere a quest'email!";
mail($email, $subject, $message, "From: $sitename <$adminemail>\nX-Mailer: PHP/" . phpversion());
echo 'Le informazioni per il tuo account ti sono stati inviati nella tua casella email! Controlla la tua email!';
}
?>
Invece di inviare i dati della registrazione nel db, mi esce questa scritta: