• 切换模式
  • 返回顶部
  • 返回
  • 首页

PHP Redis Session限制单用户的访问次数[附件]

本人测试系统: CentOS Linux 7.4.1708 (Core)  Apache 2.4  PhP7.1function frequent ($seconds,$counting,$jump){ $redis=new Redis(); // Redis 实例 $redis->connect ('127.0.0.1',6379); //连接本地的 Redis 服务 session_start(); //初始SESSION $key=isset($_SESSION['r_key']) ? $_SESSION['r_key'] : null; //首次是空值 $check=$redis->exists ($key); //检查 $key 是否存在 if ($check){ //首次 不存在 $redis->incr ($key); //首次$key不存在初始数字值

发表于 : 2017-10-04   ·  1414 人浏览
Hawk

PHP Redis限制单ip的访问次数

本人测试系统: CentOS Linux 7.4.1708 (Core)  Apache 2.4  PhP7.1<?php $redis = new Redis(); $redis->connect('127.0.0.1', 6379); $key=get_real_ip(); //限制次数为10 $limit = 10; $check = $redis->exists($key); if($check){ $redis->incr($key); $count = $redis->get($key); if($count > $limit){ exit('请求太频繁,请稍后再试!'); } }else{ $redis->incr($key); //限制时间为60秒 $redis->expire($key,60); } $count = $redis->get($key); echo '第 '.$count.' 次请求';

发表于 : 2017-10-03   ·  2059 人浏览
Hawk
Hawk

Hawk

别固执的认为某事必须 !

热门标签
  • 软件
  • Windows
  • Python
  • PHP
  • centos7
  • centos
  • python3
  • Nginx
  • MySQL
  • IP
  • DNS
  • WordPress
  • typecho
  • Win10
  • django
关于站长
  • 358534040
  • dyhawk@qq.com
  • Github.com/DYH89
2015 - 2025 Hawk. All Rights Reserved.
鄂公网安备42900402000705号 鄂ICP备14018555号-8号