同一台电脑,如何限制他在一分钟内只能访问5次某个域名的动态页面。超过五次的,就跳转到指定静态页。
同一台电脑,如何限制他在一分钟内只能访问5次某个域名的动态页面。超过五次的,就跳转到指定静态页。
回复讨论(解决方案)
这样做的意义是什么呢?减轻服务器压力?
这样做的意义是什么呢?减轻服务器压力?
一个IP就看作是一个电脑,在后台做一个访问次数池,定时每分钟清空一次,访问一次对应ip加一
IP不行,可以用cookie
IP不行,可以用cookie
求案例代码。。。
我想到了用cookie限制,但是不知道具体怎么写才合理高效。。
纯用JS操作cookie就可以了啊
<?php$filePath = '';$uuid = isset($_COOKIE['UUID']) ? $_COOKIE['UUID'] : false;//第一次访问if ($uuid === false){ //生成唯一的cookieID $userCookieId = md5($_SERVER['REMOTE_ADDR'].time());//SERVER_ADDR setcookie('UUID', $userCookieId); logVisitCount('1',"{$filePath}{$userCookieId}.txt"); echo 'first visit!'; exit;}//得到访问次数$visitCount = @file_get_contents("{$filePath}{$uuid}.txt");if ($visitCount === false){ $visitCount = 1; logVisitCount('1', "{$filePath}{$uuid}.txt");}else{ if ($visitCount > 5) { echo "It's max"; exit; } $visitCount++; logVisitCount($visitCount, "{$filePath}{$uuid}.txt");}echo "visit count : {$visitCount}";function logVisitCount($str, $file){ $handle = fopen($file, 'w'); fwrite($handle, $str); fclose($handle);}
简单写了一下,你改改吧。。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Alipay PHP...

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

The application of SOLID principle in PHP development includes: 1. Single responsibility principle (SRP): Each class is responsible for only one function. 2. Open and close principle (OCP): Changes are achieved through extension rather than modification. 3. Lisch's Substitution Principle (LSP): Subclasses can replace base classes without affecting program accuracy. 4. Interface isolation principle (ISP): Use fine-grained interfaces to avoid dependencies and unused methods. 5. Dependency inversion principle (DIP): High and low-level modules rely on abstraction and are implemented through dependency injection.

How to automatically set the permissions of unixsocket after the system restarts. Every time the system restarts, we need to execute the following command to modify the permissions of unixsocket: sudo...

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

Sending JSON data using PHP's cURL library In PHP development, it is often necessary to interact with external APIs. One of the common ways is to use cURL library to send POST�...

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.
