gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:40:06 32 4
gpt4 key购买 nike

我正在使用 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/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com