search
HomeBackend DevelopmentPHP ProblemHow to ban proxy ip access in php

How to disable proxy IP access in php: first determine the proxy IP through "empty($_SERVER['HTTP_VIA']) or exit('Access Denied');"; then set the monitoring variables; then process the monitoring Result; finally jump to the attacker's server address.

How to ban proxy ip access in php

Recommendation: "PHP Video Tutorial"

PHP prevents quick page refresh proxy ip access

The website received some CC attacks a few days ago, which was quite depressing. . . Let me share here, the method to prevent the automatic refresh of the web page and the method to prevent the proxy IP from accessing the website. The codes are separate. The two functions are used. You can use which one. You can customize the time interval. This code can not only prevent CC attacks, but also prevent All kinds of things can be used as long as they are added to the header. It is very useful. No more nonsense. Just go to the code:

<?php
/**
* @无作为
* www.wuzuowei.com
*/
//代理IP直接退出
empty($_SERVER[&#39;HTTP_VIA&#39;]) or exit(&#39;Access Denied&#39;);
//防止快速刷新
session_start();
$seconds = &#39;3&#39;; //时间段[秒]
$refresh = &#39;5&#39;; //刷新次数
//设置监控变量
$cur_time = time();
if(isset($_SESSION[&#39;last_time&#39;])){
$_SESSION[&#39;refresh_times&#39;] += 1;
}else{
$_SESSION[&#39;refresh_times&#39;] = 1;
$_SESSION[&#39;last_time&#39;] = $cur_time;
}
//处理监控结果
if($cur_time - $_SESSION[&#39;last_time&#39;] < $seconds){
if($_SESSION[&#39;refresh_times&#39;] >= $refresh){
//跳转至攻击者服务器地址
header(sprintf(&#39;Location:%s&#39;, &#39;http://127.0.0.1&#39;));
exit(&#39;Access Denied&#39;);
}
}else{
$_SESSION[&#39;refresh_times&#39;] = 0;
$_SESSION[&#39;last_time&#39;] = $cur_time;
}
?>

The above is the detailed content of How to ban proxy ip access in php. For more information, please follow other related articles on the PHP Chinese website!

Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Atom editor mac version download

Atom editor mac version download

The most popular open source editor

VSCode Windows 64-bit Download

VSCode Windows 64-bit Download

A free and powerful IDE editor launched by Microsoft

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

MantisBT

MantisBT

Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools