<?php
require_once("connetti.php");
if (!isset($_POST['reg'])) {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Modulo d'iscrizone</title>
<center> <H1>BENVENUTO NEL SITO D'ISCIRIZIONE PROVA</H1>
<form action= '' method="POST">
<font face="Comic Sans MS">
Nome: <input type="text" name="nome" maxlength="30" size ="32"> <br> <br>
Cognome: <input type="text" name="cognome" maxlength="30" size ="32"> <br> <br>
Username: <input type="text" name="username" maxlength="30" size ="32"> <br> <br>
Email: <input type="text" name="email" maxlength="40" size ="42"> <br> <br>
Rip-Email: <input type="text" name="ripemail" maxlength="40" size ="42"> <br> <br>
Password: <input type="password" name="password" maxlength="12" size ="14"> <br> <br>
Rip-Passw: <input type="password" name="passw" maxlength="12" size ="14"> <br> <br>
</font>
<center>
<input type="submit" name="reg" value="Invio iscrizione" />
<input type="submit" name="uscita" value="Uscita" />
</center> </form>
</head>
<body>
<?php
} else {
$nome = mysql_real_escape_string(strtolower(trim ($_POST['nome'])));
$cognome = mysql_real_escape_string(strtolower(trim ($_POST['cognome'])));
$username = mysql_real_escape_string(strtolower(trim ($_POST['username'])));
$password = mysql_real_escape_string(trim ($_POST['password']));
$passw = mysql_real_escape_string(trim ($_POST['passw']));
$email = mysql_real_escape_string(trim ($_POST['email']));
$ripemail = mysql_real_escape_string(trim ($_POST['ripemail']));
$pass = mysql_real_escape_string(md5(trim($_POST['password'])));
$ok_ko ="";
if($nome ==""){$ok_ko .= "Attenzione: il campo nome deve essere compilato. <br> <br>";}
if($cognome ==""){$ok_ko .= "Attenzione: il campo cognome deve essere compilato. <br> <br>";}
if($username ==""){$ok_ko .= "Attenzione: il campo username deve essere compilato. <br> <br>";}
if($email ==""){$ok_ko .= "Attenzione: il campo email deve essere compilato. <br> <br>";}
if($password ==""){$ok_ko .= "Attenzione: il campo password deve essere compilato. <br><br>";}
if($password != $passw){$ok_ko .= "Attenzione: le due password non coincidono. <br> <br>";}
$checkusername=mysql_query("SELECT username FROM utenti WHERE username='$username'");
$vuota=mysql_num_rows($checkusername);
if($vuota > 0){
echo "<br> <br> <h1> Attenzione: lo username: ".$username." è già presente nell'archivio. Si prega di cambiare email. Grazie !!! </h1>";
echo "<meta http-equiv='Refresh' content=4; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
exit();
}
if(!filter_var($email, FILTER_VALIDATE_EMAIL)||!filter_var($ripemail,FILTER_VALIDATE_EMAIL)){
$ok_ko .= "indirizzo email non valido<br>";
if($email != $ripemail){$ok_ko .= "Attenzione: le due email non coincidono. <br> <br>";}
}
$checkemail=mysql_query("SELECT email FROM utenti WHERE email='$email'");
$vuota=mysql_num_rows($checkemail);
if($vuota > 0){
echo "<br> <br> <h1> Attenzione: l'email: ".$email." è già presente nell'archivio. Si prega di cambiare email. Grazie !!! </h1>";
echo "<meta http-equiv='Refresh' content=4; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
exit();
}
if($email != $ripemail){$ok_ko .= "Attenzione: le due email non coincidono. <br> <br>";}
}
if($ok_ko !=""){
echo "<h1>$ok_ko</h1>";
echo "<meta http-equiv='Refresh' content='3; URL=".htmlspecialchars($_SERVER['PHP_SELF'])."'>";
exit();
}else{
$query="INSERT INTO utenti(nome, cognome, username, email, password) VALUES('$nome','$cognome','$username','$email','$pass')";
$q_i=mysql_query($query);//qui se registra, se bool false errore, se resuorce... è a posto
var_dump($q_i);
// Parte riguardante l'invio email
//require_once ("/class.phpmailler.php");
require_once 'phpmailer/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Username = "xxx@gmail.com";
$mail->Password = "";
$mail->SetFrom("no_replay@myserver.org");
$mail->Subject = "Attivazione account.";
$mail->CharSet = "UTF-8";
$mail->MsgHTML('Grazie di esserti iscritto. <a href="http://utenti/fabio/MegaLaboratorio/login.php?username=' . $_POST['username'] .'&passw=' . $_POST['passw'] .'&attivo=' . $_POST['attivo']=1 .'">clicca qui per attivare</a></b>'." "."per attviare l'account. Grazie.");
Grazie di esserti iscritto. <a href="http://utenti/fabio/MegaLaboratorio//attivazione.php?username=' . $_POST['username'] .'&email=' . $_POST['email'] .'">clicca qui</a> "per attivare il tuo account. Grazie.");
$mail->AddAddress($_POST['email']);
if(!$mail->Send()) {
echo "Errore nell'inviare l'email: " . $mail->ErrorInfo;
} else {
echo "Messaggio inviatro correttamente!";
}
echo "<h1> <br>Utente registrato correttamente. E' stata inviata un'email di conferma per attivare l'account</h1>";
header("Refresh: 2;URL=login.php");
}
?>