通过 PHP 限制活动
我有一个社交网络,允许用户发布博客、提出问题和消息。我们在垃圾邮件方面遇到了一些小问题。例如,我们让用户注册,并每分钟写大约 6 个博客试图推销东西。
我正在寻找一种通过用户 ID 限制这些活动的快速方法,假设只允许他们每天发布 3 个博客。
我将用户存储在 $auth
变量中,并通过 OOP 通过 $auth->id
调出它们,以便更具体。
正在寻找一种快速、简单的方法通过 php 来完成此操作。
提前致谢/**编辑*****/
这是我到目前为止所拥有的,并且我确信 $too much 正在计算,但由于某种原因,我的 if(statement
并没有阻止第四篇博客的发帖。这里是代码
I have a social network that allows users to post blogs, ask questions, and message. We have had a slight issue with spamming. For example, we had users sign up, and write about 6 blogs a minute trying to sell stuff.
I am looking for a quick way to limit these activities by the id of the user, let's say only allowing them to post 3 blogs a day.
I have the users stored in a $auth
variable and through OOP bring them up by $auth->id
for example to be more specific.
Looking for a fast,simple way to do this via php.
thanks in advance /**EDIT*****/
this is what I have so far, and I know for sure $too many is counting as it should, but for some reason my if(statement
is not stopping the 4th blog from posting. HERE is the code
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
像 CAPTCHA 这样的东西是合适的。但是,如果是手动输入,则几乎无法阻止它们。无论如何,您没有理由不能实现这两种方法。
我假设您的博客表中有一个
created
字段。只需在表中查询具有今天日期的博客数量,然后再允许发布另一个博客即可。不确定您使用的是什么数据库/API。在 MySQL 中,你可以这样做:Something like CAPTCHA would be appropriate. However, if they're being entered manually, it will do little to stop them. Regardless, no reason you can't implement both methods.
I'm assuming you have a
created
field in your blogs table. Simply query the table for the number of blogs with today's date before allowing another to be posted. Not sure what database/API you're using. In MySQL, you could do:当用户撰写并提交帖子时,将他们发布的日期保存在帖子的表格中。选择并计算他们今天发布的次数。如果他们低于限制,请允许该帖子,否则向他们提供错误/警告消息。
When the user writes and submits a post, save the date they posted on the post's table. Select and count the amount of times they posted today. If they are under their limit, allow the post or else give them the error/warning message.
发布帖子后,请执行以下操作:
...或者您可以只使用验证码(如其他人提到的)。这就是他们的目的。真的,你应该在注册过程中拥有一个......
When a post is made, do something like:
...or you could just use a CAPTCHA (as mentioned by others). That's what they're for. Really, you should have one in the signup process...
我承认我对 PHP 编程几乎一无所知,但另一种选择(或验证码的补充)是使用诸如 StopForumSpam
有一个 如何在这里使用它(不知道它有多好,因为我还没有编写 PHP 代码):)
I'll admit I know next to nothing on PHP programming, but another option (or addition to the CAPTCHA) would be to use a service such as StopForumSpam
There's an example of how to use it here (no idea how good it is, as I don't code PHP (yet)) :)