PHP 检测字符串中有多少个 URL

发布于 2024-08-04 00:00:31 字数 221 浏览 3 评论 0原文

我正在为网站实现联系表单,我想避免使用验证码,因为我认为它会对用户体验产生负面影响。

相反,我决定尝试检测随消息一起提交的 URL 数量。

我正在从 $_POST 提交中以字符串形式检索消息。我知道内置的 PHP 函数(例如 stristr())可以让我确认消息中存在子字符串,但我想要的是计数。

此外,就垃圾邮件检测而言,是否会匹配“”之类的内容合适吗?

干杯。

I'm implementing a contact form for a website, and I'd like to avoid using a captcha because I believe it has a negative effect on user experience.

Instead, I've decided to trial detecting the number of URLs that have been submitted with the message.

I am retrieving the message as a string from the $_POST submission. I know inbuilt PHP functions such as stristr() can give me confirmation that a substring exists within the message but what I'd like is the count.

Also, in terms of spam detection, would a match on something like "</a>" be appropriate?

Cheers.

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

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

发布评论

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

评论(2

逆蝶 2024-08-11 00:00:31

substr_count($text, "http")
http://www.php.net/manual/en/function。 substr-count.php

请注意,这还不够,而且也不允许用户将未经过滤的数据输入到呈现为 html 的表单字段中。

由于跨站点脚本 http:// /www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting

我建议使用 http://htmlpurifier。 org/ 删除任何恶意代码。

最后,对于垃圾邮件过滤,我建议 http://akismet.com/

祝你好运。

substr_count($text, "http")
http://www.php.net/manual/en/function.substr-count.php

Note that isn't sufficient, but neither is allowing users to enter unfiltered data into your form fields that gets rendered as html.

I shouldn't be able to put javascript in there either due to Cross Site Scripting http://www.owasp.org/index.php/Top_10_2007-Cross_Site_Scripting

I'd recommend using http://htmlpurifier.org/ to remove any malicious code.

Finally for spam filtering I'd recommend http://akismet.com/

Good luck.

两人的回忆 2024-08-11 00:00:31

如果这是联系表单,则无需接受 html。只需对整个内容进行编码并限制来自同一 IP 的帖子数量或限制消息之间的时间。

是的,你可以限制网址的数量,但我认为这没有效果

if this is a contact form, there is no need to accept html. just encode the whole content and limit the number of posts from the same ip or limit the time between messages.

yes you could restrict the number of urls, but i don't think this is effective

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