How to ban proxy ip access in php

藏色散人
Release: 2023-03-07 10:48:01
Original
3006 people have browsed it

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;
}
?>
Copy after login

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!

Related labels:
php
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template