Ecco il mio pieno scenario di soluzione:
CREATE TABLE signup (
id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(30) NOT NULL,
password VARCHAR(30) NOT NULL,
email VARCHAR(30) NOT NULL,
token VARCHAR(30) NOT NULL,
verified VARCHAR(50),
registration_date TIMESTAMP,
maxdate TIMESTAMP
);
Aggiungi pagina di registrazione signup.php
Aggiungere il seguente modulo:
<form name="signupform" method="post" action="process.php">
Username:
<input type="text" name="username">
<br> Password:
<input type="text" name="password">
<br> Email:
<input type="text" name="email">
<br>
<input type="submit" value="Signup">
</form>
Crea process.php pagina:
<?php
$username = $_POST['username'];
$email = $_POST['email'];
$password = $_POST['password'];
date_default_timezone_set('America/New_York');
$registration_date = date('Y-m-d H:i:s');
$verified = 0;
$maxdate = date('Y-m-d H:i:s', strtotime($registration_date . ' +1 day'));
$salt = uniqid(mt_rand() , true);
$token = msha1(registration_date . md5($salt));
$sql = "INSERT INTO signup (username, password, email, token, verified, registration_date, maxdate) VALUES ('$username', '$password', '$email', '$token', '$verified', '$registration_date', '$maxdate')";
if (mysqli_query($conn, $sql))
{
$msg = 'Please click this link to verify your email: http://www.yourdomain.com/verifyemail.php?token=' . $token;
mail($email, $subject, $msg);
}
else
{
echo mysql_error();
}
?>
creare in seguito verifyemail.php:
<?php
$token = $_REQUEST['token'];
date_default_timezone_set('America/New_York');
$current_time = date('Y-m-d H:i:s');
$sql = "SELECT * FROM users WHERE token='$token' AND maxtime >'$current_time' AND verified=0";
$result = mysqli_query($conn, $sql);
$notverified = mysqli_num_rows($result);
if ($notverified)
{
$sql = "update signup set verified=1 where token='$token'";
$result = mysqli_query($conn, $sql);
if ($result)
{
echo 'Email verified';
}
else
{
echo 'Error';
}
}
else
{
echo 'Link expired';
}
?>
possibile duplicato del [Generazione di codice di conferma per una mail di conferma] (http://stackoverflow.com/questions/2088969/generating-confirmation-code-for-an-email-confirmation) – Gordon
@ Gordon: non una domanda duplice, collegata chiede solo di generare numeri casuali. Questo ha chiesto dell'intera procedura da un livello superiore. – Borealid
@Borealid yes dup. Il corpo della domanda e le risposte combinate contengono tutto ciò che c'è da sapere per rispondere a questa domanda qui. – Gordon