-3

我尝试使用 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());

       }

    }

  }

}
?>
4

1 回答 1

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........';
}
于 2012-10-10T10:13:31.963 回答