如何阻止垃圾邮件发送者将 http 输入到数据库表单中

发布于 2024-08-25 19:19:38 字数 104 浏览 8 评论 0原文

我有一个将信息发送到数据库表中的表单。我用 Javascript 检查了它,但是当 Javascript 关闭时,阻止垃圾邮件发送者使用 PHP 输入 http 等内容到数据库的最佳方法是什么?

I have a form that sends info into a database table. I have it checked with a Javascript but what is the best way to stop spammers entering http and such into the database with PHP when Javascript is turned off?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

记忆消瘦 2024-09-01 19:19:38

您可以在表单上实施验证码:

http://en.wikipedia.org/wiki/CAPTCHA

编辑:也一定要验证服务器端的表单数据并像往常一样检查 html 标签等,但验证码应该有助于防止自动垃圾邮件攻击。

You could implement a CAPTCHA on the form:

http://en.wikipedia.org/wiki/CAPTCHA

Edit: Also definitely verify form data on the server side and check for html tags etc as usual, but the CAPTCHA should help against automated spam attacks.

月隐月明月朦胧 2024-09-01 19:19:38

永远不要相信客户。始终验证服务器端的所有数据。用于表单验证的 JavaScript 只是一个附加功能。您可以从基本的 PHP 函数开始检查内容是否包含您不喜欢的某些字符串,例如。 “http://”。

if (strpos('http://', $_POST['message']) !== false) { /* refuse */ }

Never trust the client. Always validate all data on server side. JavaScript for form validation can just be an additional feature. You could start with basic PHP functions to check if the content contains certain strings you don't like, eg. "http://".

if (strpos('http://', $_POST['message']) !== false) { /* refuse */ }
一江春梦 2024-09-01 19:19:38

您可以使用CSRF保护来防止垃圾邮件发送者,我发现它非常有效。

它是什么工作原理

另一种偷偷摸摸的方法是包含一个“蜜罐”字段 - 一个永远不应该与内容一起提交的隐藏字段。如果已满,您就知道这是垃圾邮件。这两种方法都不需要烦人的验证码。

You can use CSRF protection to prevent spammers, I have found it quite effective.

What it is and how it works

Another sneaky method is to include a "honeypot" field - a hidden field that should never be submitted with content. If it's filled, you know it's spam. Neither of these methods require an annoying CAPTCHA.

开始看清了 2024-09-01 19:19:38

有两件事需要考虑,应该并行实施(也许还有更多)。

  1. 验证码(如前所述)
  2. 在服务器端验证您的数据!你写的是你通过 javascript 来做到这一点。这很好,但同样的验证过程应该用 PHP 编写。

好吧,对于验证码,无论如何你都必须在服务器端进行验证。但即使您决定不实施验证码,您也应该在服务器端进行数据验证。

There are two things to consider which should be implemented in parallel (maybe there's more).

  1. Captcha (as mentioned before)
  2. Verify your data on server side! You wrote you do this by javascript. This is good, but the very same verification proccess should be written in PHP.

Well, for CAPTCHA you'll have to make it's verification on server side anyway. But even if you decide not to implement captcha, you should make data verification on server side.

究竟谁懂我的在乎 2024-09-01 19:19:38

我建议在之前使用 htmlentities() 函数做你的插入。

显然,您的插入应该使用 参数化查询 进行交互数据库也是如此。验证码当然是一个选项,但它更多的是限制某人可以发布的频率,而不是他们可以发布的内容。使用 hmtl 转义(同样是 htmlentities() 函数)来防止用户输入您不想要的内容。

I suggest using the htmlentities() function before doing your insert.

Obviously your insert should be done using parametrized queries to interact with the database as well. captcha is certainly an option, but it more serves to limit how often someone can post, not what they can post. Use hmtl escaping (again, the htmlentities() function) to prevent the user from inputting things you don't want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文