以下是一个简单的PHP实例,用于统计一个页面在特定时间段内的请求次数。我们将使用内置的`$_SERVER`超全局变量来检测请求类型,并使用文件系统来存储和更新请求次数。
```php

// 定义一个文件用于存储请求次数
$counterFile = 'request_counter.txt';
// 检查请求次数文件是否存在,如果不存在则创建并初始化计数为0
if (!file_exists($counterFile)) {
file_put_contents($counterFile, 0);
}
// 读取当前请求次数
$counter = file_get_contents($counterFile);
// 更新请求次数
$counter++;
// 将更新后的请求次数写回文件
file_put_contents($counterFile, $counter);
// 打印当前请求次数
echo "







