【发布时间】:2014-07-17 06:00:12
【问题描述】:
经过更多故障排除后,我相信我找到了问题所在。我们为我们的产品使用二维码标签,当扫描二维码时,它会将用户带到运行此脚本的 URL。如果我手动输入 URL,或者如果我使用我们定制的 QR 扫描仪应用程序,那么用户将收到一封电子邮件。但是,如果我使用任何其他 QR 扫描应用程序,那么它将发送多封电子邮件。我怎样才能使这个脚本在每次加载 URL 时只运行一次,即使它来自第三方应用程序?
<?php
$queryString = $_SERVER['QUERY_STRING'];
$count=-6;
$id=substr($queryString,$count,6);
//db connection
$db = new mysqli('localhost', '*****', '*****', '*****');
if (mysqli_connect_errno()) {
echo 'Error: Could not connect to database. Please try again later.';
exit;
}
$query = "SELECT * FROM `****` where id = '$id'";
$result = $db->query($query);
$row = $result->fetch_assoc();
$email = $row['email'];
$ownername = $row['ownername'];
$petname = $row['petname'];
//check to see if tag has been registered
if ($email != "") {
//send email
$datetime = date("D M j G:i:s T Y");
$subject = "Alert";
$mailheader.= "From: " . "Tag Team <support@tag.com>\n";
$mailheader.= "X-Sender: " . "support@tag.com\n";
$mailheader.= "Return-Path: " . "support@tag.com\n";
$mailheader .= "Bcc: support@tag.com";
$body .= "Dear " . $ownername . ", \n\n";
$body .= "" . $petname . "'s Tag has just been scanned.\n\n";
$body .= "Click here to Login :\n";
$body .= "http://www.tag.com\n";
$body .= "********************\n\n";
$body .= "Regards,";
$body .= " \n\n";
$body .= "Tag Team";
$body .= " \n\n";
$body .= "Keeping Pets Safe and Found";
mail($email, $subject, $body, $mailheader ) or die ("Mail could not be sent.");
//end email alert
}
header("Location: http://www.smartphonepettag.com/id/profile.php?id=$id");
mysql_close($db);
?>
【问题讨论】:
-
你是从其他地方调用这个文件吗?
-
这个页面是如何加载的?如果是 GET 请求,则可能是页面被多次加载。尝试使该页面仅通过 POST 可用。非幂等请求(具有副作用的请求)不应通过 GET 发生。 en.wikipedia.org/wiki/Idempotence
-
我们的用户访问 p7p.co/(6digitID#)。这会加载此脚本,然后重定向
-
此代码仅发送一封电子邮件。您的问题源于其他原因。
-
我编辑了我的问题。