使用php验证电子邮件

时间:2013-10-08 02:56:50

标签: php email-verification

我是新来的,我正在为客户继续以前的开发者网站。 在用户注册网络成员后,此网站将向用户发送验证电子邮件。 电子邮件将发送给用户,但我现在的问题是验证无效。当用户点击验证链接时,它会链接到verification.php但显示空白页面。 我不知道问题出在哪里。 这是account_verification.php文件:

session_start();  
require_once 'cms/configuration.php';

$username = $_GET['e_username'];
$key = $_GET['key'];

$sql = "SELECT * FROM member WHERE username = '$username'";
$result = mysql_query($sql);
$row = mysql_fetch_array($result);
$memberID = $row['id'];

if ($key == md5($username.$row['id']))
{
    $sql = "UPDATE member SET verified = '1' WHERE id = '{$row['id']}'";    
    $result = mysql_query($sql);

    echo '  <script type="text/javascript">
            alert("Your account is activated."); 
            window.location = "homepage.php"; 
            </script>';
}
?>

这是membersignup.php文件:

<?php
session_start();
require_once 'cms/configuration.php';
include "includes/phpmailer.php";

foreach ($_POST as $key => $value)
{
    $_POST[$key] = $value;
}


$e_username = trim($_POST['username']);
$password = $_POST['password'];
$ic_no = $_POST['ic_no'];
$email = $_POST['email'];
$dob = $_POST['dob'];
$contact = $_POST['contact'];
$address = $_POST['address'];
$comp_name = $_POST['comp_name'];
$comp_address = $_POST['comp_address'];
$comp_contact = $_POST['comp_contact'];
$comp_fax = $_POST['comp_fax'];
$comp_email = $_POST['comp_email'];
$about_us = $_POST['about_us'];
$datetime = $_POST['datetime'];

;
$result = mysql_query("SELECT username FROM member WHERE username='$e_username'");
$num_records = mysql_num_rows($result);

if ($num_records !=0){
    echo "Please use different username.";
    exit();
}


$sql = sprintf("INSERT INTO member (username, password, ic_no,email, birthday, contact, address, company_name, company_address, company_contact, company_fax, company_email, about_us, register_date)
                VALUES ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s',NOW())",


        mysql_real_escape_string($e_username),
        md5($password),
        mysql_real_escape_string($ic_no),
        mysql_real_escape_string($email),
        mysql_real_escape_string($dob),
        mysql_real_escape_string($contact),
        mysql_real_escape_string($address),
        mysql_real_escape_string($comp_name),
        mysql_real_escape_string($comp_address),
        mysql_real_escape_string($comp_contact),
        mysql_real_escape_string($comp_fax),
        mysql_real_escape_string($comp_email),
        mysql_real_escape_string($about_us),
        mysql_real_escape_string($datetime)
);
$result = mysql_query($sql) or die(mysql_error());
$insertID = mysql_insert_id();
$key = md5($_POST['username'].$insertID);
$link = "http://___/account_verification.php?username={$_POST['username']}&key=$key";
$body = "<div>
            <p style='padding:10px;'>
            Hello {$_POST['username']}!
            </p>
            <p style='padding:10px;'>
            Thank you for creating an account at ___.
            </p>
            <p style='padding:10px;'>
            Please keep this e-mail for your records. Your account information is as follows:<br/>
            Username : $e_username <br/>
            Password : {$_POST['password']}
            </p>
            <p style='padding:10px;'>
            Verify your account to complete your registration by clicking the link:<br/>
            <a href='$link' target='_blank'>$link</a>
            </p>
            <p style='padding:10px;'>&nbsp;</p>
            <p style='padding:10px;'>
            Thanks,<br/>Admin
            </p>
        </div>";
$subject = "Member Registration and Verification";
if ($result)
{
    $sendMailResult = sendPHPMail('noreply@___.com', '___', $_POST['email'], $subject, $body);
    if($sendMailResult == TRUE)
        echo 1;
    else
        echo "There's problem sending validation mail to your email. Please try again later.";
}
else
{
    echo "There's problem saving your registration details to our database. Please try again later.";   
}

?>

任何人都可以帮我找到这里的问题吗?

1 个答案:

答案 0 :(得分:0)

当您实际只发送网址$username = $_GET['e_username'];

时,您正在搜索与username匹配的用户

因此,您的account_verification.php应为

session_start();  
require_once 'cms/configuration.php';

$username = $_GET['username'];
$key = $_GET['key'];

$sql = "SELECT * FROM member WHERE username = '$username'";
etc ...

您对此脚本的链接应如下所示:(注意:您的用户名变量已更改为$ _POST ['e_username']

$link = "http://___/account_verification.php?username={$_POST['e_username']}&key=$key";