我尝试使用PHP进行用户注册和电子邮件验证,一切响应都非常好,但在用户提交注册表单之后某个点,然后表单发布到verify.php
然后脚本将发送激活码到用户的电子邮件。
错误是激活邮件发送到用户邮箱的那一刻,页面应显示:
谢谢!已向{Form.email}发送电子邮件。要完成注册,请单击发送到您的电子邮件地址的电子邮件验证链接。
相反,它会自动刷新页面并将用户重定向到registrationcomplete.php
页面。假设在用户验证后会出现。
我使用了以下代码:
<?php
require ('Connections.php');
$activationkey = mt_rand() . mt_rand() . mt_rand() . mt_rand() . mt_rand();
$name = mysql_real_escape_string($_POST['name']);
$country = mysql_real_escape_string($_POST['country']);
$state = mysql_real_escape_string($_POST['state']);
$add = mysql_real_escape_string($_POST['add']);
$phone = mysql_real_escape_string($_POST['phone']);
$email = mysql_real_escape_string($_POST['email']);
$userid = mysql_real_escape_string($_POST['userid']);
$password = mysql_real_escape_string($_POST['password']);
$lrname = mysql_real_escape_string($_POST['lrname']);
$lraccount = mysql_real_escape_string($_POST['lraccount']);
$wmz = mysql_real_escape_string($_POST['wmz']);
$form_submitt = $_POST['button'];
if ($form_submitt == true){
$sql = "INSERT INTO customers (`activationkey`, `name`, `country`, `state`, `add`, `phone`, `email`, `lrname`, `lraccount`, `comment`, `wmz`, `okpay`, `userid`, `password`, `status`) VALUES ('$activationkey', '$name', '$country', '$state', '$add', '$phone', '$email', '$lrname', '$lraccount', '', '$wmz', '', '$userid', '$password', 'verify');";
mysql_query($sql) or die(mysql_error());
##Send activation Email
$to = $_POST['email'];
$subject = "Complete registation";
$message = "Welcome to sitename!\r\rYou, or someone using your email address, has completed registration at www.sitename.com.\r\r You can complete registration by clicking the following link:\rhttp://www.sitename.com/verify.php?$activationkey \r\rIf this is an error, ignore this email and you will be removed from our mailing list.\r\rRegards,\r\r www.sitename.com Team";
$headers = 'From: noreply@sitename.com' . "\r\n" .
'Reply-To: noreply@sitename.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
}
?>
<?php
##User isn't registering, check verify code and change activation code to null, status to activated on success
if(isset($_SERVER['QUERY_STRING'])){
$queryString = $_SERVER['QUERY_STRING'];
$query = "SELECT * FROM `DBName`.`customers`";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
if ($queryString == $row['activationkey']){
$sql = "UPDATE `DBName`.`customers` SET `activationkey` = '', `status` = 'verified' WHERE `customers`.`id` = $row[id];";
mysql_query($sql) or die(mysql_error());
echo "<meta http-equiv='refresh' content='0;url=registrationcomplete.php'>";
if (!mysql_query($sql)){
die('Error: ' . mysql_error());
}
}
}
}
?>
答案 0 :(得分:0)
替换,
echo "<meta http-equiv='refresh' content='0;url=registrationcomplete.php'>";
到
header('location:verify.php?action=success');
exit();
现在使用action
变量可以显示消息
if(isset($_GET['action']) && $_GET['action'] == "success"){
echo 'Thank you message........';
}