php - 限制给定秒数的 IP 访问

标签 php mysql cakephp time

我正在使用 CakePHP,我需要将特定页面上的页面浏览量限制在一小段随机秒数内。然而,我编写代码,有时,即使不应该,阻塞触发器也会被欺骗。

$site_seconds = "100";          
$get15 = $site_seconds * 5 / 100;
$ip_session = $credits_one - $get15;
$ip_session_time = round($ip_session);

我使用它是为了获得比实际访问时间更少的数字,它是为了避免像我遇到的错误而创建的,并不是很有帮助。 因此,如果我们有 100 秒,我们将计算 95 秒。

    $conditions_check = array(
        'date >=' => date('Y-m-d H:i:s', strtotime("-$ip_session_time SECONDS")),
        'user' => $user_id,
        'value1' => $ip,
        'type' => '3'
    );

       /// we check if the condition has any rows 
        if ($this->Log->hasAny($conditions_check)){ 
           // If found I send a private message to the user
             $this->Log->set('date', date('Y-m-d H:i:s')); // time here is only for ordering when displayed to user
             $this->Log->set('user', $user_id);
             $this->Log->set('value1', $ip);
             $this->Log->set('value2', "No credits received for this visit. To many conditions from same IP.");
             $this->Log->set('value3', "1");
             $this->Log->set('type', '4');
             $this->Log->save();
            }else{
           // The code runs
            }

我尝试使用 strtotime(*now*); 但更糟糕的是,错误每次都出现,使用这段代码,可能每 2 分钟一次。

最佳答案

我意识到我的错误在哪里,我设置了时间,但是当我检查用户访问速度是否太快时,我检查了新计时器,如果数字高于旧计时器,则会触发错误。 修复它的一种方法是插入一个新的时间值,即何时应该释放 IP。

感谢@Stefan 的帮助。

关于php - 限制给定秒数的 IP 访问,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31365243/

相关文章:

python - django 中的分组依据、不同值、计数

mysql - SQL查询查询

iphone - 使用我自己的服务器创建安全 ios 身份验证的正确原因是什么

php - 如何在类中包含定义常量的文件(及其范围)

php - 如何在计算闰年的同时使用 DateTime 计算自年初以来的天数?

mysql - 第 5 行警告 : mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in/home/a8107556/public_html/index. php

mysql - 我可以查询 MYSQL 的特定数据类型吗?

php - CakePHP ACL 教程 initDB 函数警告

php - CKEDITOR - Uncaught Error : The specified element mode is not supported on element: "meta"

php - 如果字母或单词匹配,MySQL 返回所有内容?