有没有办法100%防止php邮件脚本被滥用?
我进行了搜索,发现了一些好主意,但没有什么100%解决了我遇到的这个php邮件问题。
注意:当我从服务器删除此文件时,垃圾邮件就会停止。此外,Captcha 并不是一个真正的选项,这是一个 Ajax 调用,并且需要速度快。我不是 100% 确定垃圾邮件发送者是如何做到这一点的,但任何帮助都将不胜感激。
以下是添加到表单中的 HTML 代码:
<input name="spam_stopper" value="DO NOT CHANGE THIS VALUE" style="display:none;"/>
这是我在邮件顶部添加的附加代码。尚未阻止垃圾邮件的 php 文件:
if ($_POST['spam_stopper'] != 'DO NOT CHANGE THIS VALUE') {
echo '<h3>Incorrect use of this form!</h3>';
exit;
}
if(!strpos($_SERVER['HTTP_REFERER'],'my-sample-domain-name.com'))
{
echo '<h3>Incorrect use of this form!</h3>';
exit;
}
if($_SERVER['REQUEST_METHOD'] != "POST"){
echo("Unauthorized attempt to access page.");
exit;
}
I have searched SO and have found a couple of good ideas but nothing that has 100% solved this php mail problem I am having.
NOTE: When I delete this file from the server the spam stops. Also Captcha is not really an option, this is an Ajax call and it needs to be fast. I'm not 100% sure how the spammers doing it but any help would be appreciated big time.
Here is the bit of HTML added to the form:
<input name="spam_stopper" value="DO NOT CHANGE THIS VALUE" style="display:none;"/>
Here is the additional code I added at the top of the mail.php file that hasn't stopped the spam:
if ($_POST['spam_stopper'] != 'DO NOT CHANGE THIS VALUE') {
echo '<h3>Incorrect use of this form!</h3>';
exit;
}
if(!strpos($_SERVER['HTTP_REFERER'],'my-sample-domain-name.com'))
{
echo '<h3>Incorrect use of this form!</h3>';
exit;
}
if($_SERVER['REQUEST_METHOD'] != "POST"){
echo("Unauthorized attempt to access page.");
exit;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您允许通过 POST 提交您自己的表单进行访问。那么,如果我继续在您自己的网站上使用 JavaScript(例如使用 Firebug)提交它,那么什么可以阻止我呢?
您应该在每个发送邮件请求中附带一个仅一次有效的令牌,以确保您的表单不能提交多次,即使是从您自己的网站提交也是如此。
you are allowing access via POST submission of your own form. So, if I keep submitting it using JavaScript on your own website, say, using Firebug, then what's to stop me?
You should have a once-only-valid token accompanying each send-mail request to ensure that your forms cannot be submitted more than once, even from your own website.