通过 PHP 限制活动

发布于 2024-12-18 14:16:56 字数 511 浏览 1 评论 0原文

我有一个社交网络,允许用户发布博客、提出问题和消息。我们在垃圾邮件方面遇到了一些小问题。例如,我们让用户注册,并每分钟写大约 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 技术交流群。

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

发布评论

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

评论(4

风筝在阴天搁浅。 2024-12-25 14:16:56

CAPTCHA 这样的东西是合适的。但是,如果是手动输入,则几乎无法阻止它们。无论如何,您没有理由不能实现这两种方法。

我假设您的博客表中有一个 created 字段。只需在表中查询具有今天日期的博客数量,然后再允许发布另一个博客即可。不确定您使用的是什么数据库/API。在 MySQL 中,你可以这样做:

SELECT COUNT(*) 
FROM blogs 
WHERE user_id = USERID 
AND DATE(created) = '2011-11-30'

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:

SELECT COUNT(*) 
FROM blogs 
WHERE user_id = USERID 
AND DATE(created) = '2011-11-30'
怕倦 2024-12-25 14:16:56

当用户撰写并提交帖子时,将他们发布的日期保存在帖子的表格中。选择并计算他们今天发布的次数。如果他们低于限制,请允许该帖子,否则向他们提供错误/警告消息。

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.

烟酉 2024-12-25 14:16:56

发布帖子后,请执行以下操作:

// Get last post time and number of posts today from database
$query = "SELECT
            last_post,
            posts_today
          FROM
            users
          WHERE
            id = '$auth->id'";
$result = mysql_fetch_assoc(mysql_query($query));

// See if this is the first post today
$isNewDay = date('Y-m-d') != date('Y-m-d',strtotime($result['last_post']));
$postsToday = ($isNewDay) ? 0 : (int) $result['posts_today'];

// Only add post if user is allowed
if ($isNewDay || $postsToday < 3) {
  /*
    Add the post to the database here
  */
  // Update the number of posts today in the database
  $query = "UPDATE
              users
            SET
              last_post = '".date('Y-m-d H:i:s')."',
              posts_today = '".($postsToday + 1)."'
            WHERE
              id = '$auth->id'";
  mysql_query($query);
} else {
  echo "You have already made 3 posts today!";
}

...或者您可以只使用验证码(如其他人提到的)。这就是他们的目的。真的,你应该在注册过程中拥有一个......

When a post is made, do something like:

// Get last post time and number of posts today from database
$query = "SELECT
            last_post,
            posts_today
          FROM
            users
          WHERE
            id = '$auth->id'";
$result = mysql_fetch_assoc(mysql_query($query));

// See if this is the first post today
$isNewDay = date('Y-m-d') != date('Y-m-d',strtotime($result['last_post']));
$postsToday = ($isNewDay) ? 0 : (int) $result['posts_today'];

// Only add post if user is allowed
if ($isNewDay || $postsToday < 3) {
  /*
    Add the post to the database here
  */
  // Update the number of posts today in the database
  $query = "UPDATE
              users
            SET
              last_post = '".date('Y-m-d H:i:s')."',
              posts_today = '".($postsToday + 1)."'
            WHERE
              id = '$auth->id'";
  mysql_query($query);
} else {
  echo "You have already made 3 posts today!";
}

...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...

中性美 2024-12-25 14:16:56

我承认我对 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)) :)

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