【问题标题】:php confirm email script ignores a validation stepphp 确认电子邮件脚本忽略验证步骤
【发布时间】:2015-12-09 20:13:15
【问题描述】:

我从这里下载了一个newsletter订阅php脚本:http://www.plus2net.com/php_tutorial/newsletter.php

脚本应该检查订阅者是否已经确认了他的电子邮件地址。出于某种原因,此检查总是被忽略...我没有成功显示错误消息“您已经确认订阅”。这是在脚本中。我特此复制脚本。 有人看到我在这里缺少什么吗? 该脚本带有 2 个表: nl_confirm 字段为 confirm_id、email_id、email、word、dtt 和 status(其中包含尚未确认其电子邮件的用户列表) nl_email 包含字段 email_id、电子邮件和状态,其中包含所有订阅者。如果未确认,状态为 F。 A当确认...

这是 confirm.php 脚本:

<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title></title>
<META NAME="DESCRIPTION" CONTENT=" ">
<META NAME="KEYWORDS" CONTENT="">
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<body>
<?Php
require "config.php";
$confirm_id=$_GET['confirm_id'];

$count=$dbo->prepare("
    select confirm_id,email,email_id,word,status,UNIX_TIMESTAMP(dtt) as stored_time 
    from nl_confirm where confirm_id=:confirm_id");
$count->bindParam(":confirm_id",$confirm_id,PDO::PARAM_INT,4);

if($count->execute()){
    $row = $count->fetch(PDO::FETCH_OBJ);
    if($row->confirm_id >0){
        ///////// checking the input data with record ////////////
        $flag='OK';
        $msg='';
        if($row->email_id <> $_GET['email_id']){
            $flag='NOTOK';
            $msg.='<br>Wrong Email address ';
        }

        if($row->word  <> $_GET['token']){
            $flag='NOTOK';
            $msg.='<br>Wrong Token';
        }

        if($row->email <> $_GET['email']){
            $flag='NOTOK';
            $msg.='<br>Wrong Email address ';
        }
        $present_time=time();
        $stored_time=$row->stored_time;
        //echo 'stored time : '.$row->stored_time.'<br>Present time : '. $present_time.'<br>' ;
        if(($present_time-$stored_time)>300){ 
            //// Within 300 seconds user needs to confirm subscription , you can adjust this duration ////
            $flag='NOTOK';
            $msg.='<br>It is too long. Your confirmation time expired. <a href=subscribe.php>Subscribe again</a> ';
        }

        if($row->status == 'A'){
            $flag='NOTOK';
            $msg.='<br>You have already confirmed your subscription. ' ;
        }

        if($flag=='OK'){
            $count1=$dbo->prepare("update nl_email set status='A' where email_id=$row->email_id");
            if($count1->execute()){
                $count2=$dbo->prepare("delete from  nl_confirm where confirm_id=$row->confirm_id");
                $count2->execute();
                echo "Thank you for confirming your email address. You are a subscriber of our newsletter script.
    <br> Any time you can unsubscribe by visiting a link in your newsletter. ";
            }
        }
        else{echo $msg.'<br>';}

        //////////// end of checking data /////////////
    }else{ // if condition to check confirm_id > 0
        echo " We don't have any record of pending confirmation against your email address,<br>
     you can check by <a href=subscribe.php>subscribing</a> again or contact site admin.";
    } // end of if else to check confirm_id >0
}else{ // if execute() fails 

    print_r($dbo->errorInfo()); 
}

//////////////////////////////////////////////

echo "</body></html>";

【问题讨论】:

  • var_dump($row); 显示什么?

标签: php email newsletter confirm


【解决方案1】:

你有没有试过去掉这部分代码开头和结尾的两个**?

**if($row->status == 'A'){
$flag='NOTOK';
$msg.='<br>You have already confirmed your subscription. ' ;
}**

【讨论】:

  • 嗨。对不起,那是我的错。这些**不在代码中。我想用粗体标记那部分,但显然,在代码区域中标记粗体文本在 stackoverflow 上不起作用。我将删除上面帖子中的**。但这不是问题所在:)
  • 好吧 :) 如果存在任何状态设置为 A 的记录,您是否查看过数据库?
  • 是的,确实如此。我有一个状态为 A... :/
  • 它有你试图通过 url 访问的 confirm_id? (只是问一些明显的问题,抱歉 :D)
  • .. 确实如此。我正在测试一个订阅,使用确认链接确认电子邮件地址,然后尝试再次确认...测试用例完全正确..我只是没有看到正确的错误消息出现... ://
猜你喜欢
  • 2015-03-17
  • 1970-01-01
  • 2016-12-09
  • 1970-01-01
  • 2016-05-21
  • 1970-01-01
  • 2013-05-18
  • 1970-01-01
  • 2017-02-07
相关资源
最近更新 更多