Originariamente inviato da kodode
posta il codice dove fai il salvataggio nel db (dove c'è la query)
Codice PHP:
<?php
require('connessionedb.php');
$user = mysql_real_escape_string($_POST['user']);
$user_mail = $_POST['user'];
$pass = mysql_real_escape_string(md5($_POST['pass']));
$pass_mail = $_POST['pass'];
$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string($_POST['lastname']);
$query = "SELECT * FROM user " .
"WHERE user_username = '$user' " .
"OR user_email = '$mail' ";
$result = mysql_query($query) or die (mysql_error());
if (mysql_num_rows($result) != 0)
{
while ($row = mysql_fetch_array($result))
{
if ($row['user_username'] == $user)
{
echo "
";
echo "L'username, [b]" . $row['user_username'] . "[/b] è già in uso da un altro utente, scegliere uno diverso";
echo "</p>";
}
if ($row['user_email'] == $_POST['email'])
{
echo "
";
echo "La casella E-mail, [b]" . $row['user_email'] . "[/b] è già presente nel Data Base, scegliere una diversa";
echo "</p>";
}
}
echo "
";
echo "<a href=\"registrazione.php\">";
echo "<<< Clicca qui per ritornare alla pagina precedente";
echo "</a>";
echo "</p>";
exit();
}
else
{
switch ($_GET['action'])
{
case "add":
switch ($_GET['type'])
{
case "user":
$sql = "INSERT INTO user
(user_firstname,
user_lastname,
user_username,
user_password,
user_email)
VALUES
('$firstname',
'$lastname',
'$user',
$pass',
'" . $_POST['email'] . "')";
$users = mysql_query($sql) or die(mysql_error());
$id = mysql_insert_id();
break;
}
break;
}
}
$temp = gettimeofday();
$msec = (int) $temp["usec"];
$msgid = md5(time() . $msec);
$ins = "INSERT INTO confirm
(confirm_validator,
confirm_userid)
VALUES
('$msgid',
'$id')";
$res = mysql_query($ins) or die(mysql_error());
?>
<html>
<head>
<title>Inserimento dati</title>
</head>
<body>
<?php
$to = $_POST["email"];
$toname = $_POST["firstname"];
$subject = "Completa la tua registrazione";
$boundary = "==MP_Bound_xyccr948x==";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: multipart/alternative; boundary=\"$boundary\"\r\n";
$headers .= "From: mailda [email]inserire@tuoserver.it[/email]\r\n"; //l'indirizzo email
$html_msg = "<center>";
$html_msg .= "<table width=\"500\" border=0 cellpadding=\"4\">";
$html_msg .= "<tr><td align=\"center\">";
$html_msg .= "</td></tr>";
$html_msg .= "<tr><td>Questi sono i dati della tua registrazione:";
$html_msg .= "</td></tr><tr><td>Username: <font color=\"red\">" . $user_mail . "</font>";
$html_msg .= "</td></tr><tr><td>Password: <font color=\"red\">" . $pass_mail . "</font>";
$html_msg .= "</td></tr><tr><td align=\"center\">";
$html_msg .= "</td></tr></table></center>";
$confirmmessage = "Salve " . $toname . ",\n\n";
$confirmmessage .= "per completare la tua registrazione devi cliccare sul link sottostante:\n\n";
$confirmmessage .= $html_msg . "\n\n";
// inserire il percorso esatto che porta alla nostra pagina confirm_reg.php
$confirmmessage .= "<a href=\"http://localhost/percorso pagina confirm_reg.php" .
"?id=$msgid\">Clicca qui per confermare la tua registrazione</a>";
$message = "This is a Multipart Message in MIME format\n";
$message .= "--$boundary\n";
$message .= "Content-type: text/html; charset=iso-8859-1\n";
$message .= "Content-Transfer-Encoding: 7bit\n\n";
$message .= $confirmmessage . "\n";
$message .= "--$boundary--";
$mailsent = mail($to, $subject, $message, $headers);
if ($mailsent)
{
echo "Salve" . $toname . ",
";
echo "Un messaggio è stato inviato all'indirizzo [b]" . $to . "[/b] da te fornito.
";
echo "IMPORTANTE:
";
echo "Per completare la registrazione al sito devi aprire la tua casella e-mail, leggere il messaggio di conferma e cliccare sul link che troverai all'interno.
";
} else {
echo "Errore durante l'invio dell'e-mail.";
}
?>
</body>
</html>