PHP 检测字符串中有多少个 URL
我正在为网站实现联系表单,我想避免使用验证码,因为我认为它会对用户体验产生负面影响。
相反,我决定尝试检测随消息一起提交的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
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.
如果这是联系表单,则无需接受 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