我有一个脚本,每次有人通过 Facebook 评论框发表评论时都会触发一封电子邮件。Fb.event.subscribe 在我的服务器上触发对 mail.php 的 ajax 调用,它会向我的电子邮件地址发送一封电子邮件以通知新评论。我如何使这更安全并直接阻止对 mail.php 的访问?
FB.Event.subscribe('comment.create', function (response) {
var domain = "<?= $_SERVER['SERVER_NAME']; ?>";
var url = "<?= $currentUrl ?>";
alert("comment added");
var xmlhttp;
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET","http://" + domain + "/mail.php?url=" + url,true);
xmlhttp.send();
});
** ---------- here is mail.php -------- **
<?php
$to = "MY EMAIL HERE";
$subject = "New Comment Added";
$message = "New Comment posted here: " . $_GET['url'] ;
$from = "MY EMAIL HERE";
$headers = "From:" . $from;
//mail($to,$subject,$message,$headers);
//echo $_GET['accesstoken'] ;
?>