Ban IP access code_PHP tutorial
if($_SERVER['HTTP_X_FORWARDED_FOR']){
$onlineip=$_SERVER['HTTP_X_FORWARDED_FOR'];
}elseif($_SERVER['HTTP_CLIENT_IP']){
$onlineip=$_SERVER['HTTP_CLIENT_IP'];
}else{
$onlineip=$_SERVER['REMOTE_ADDR'];
}
$onlineip =substrs($onlineip,16);
//截取IP
function substrs($content,$length) {
if($length && strlen($content)>$length){
$num=0;
for($i=0;$i<$length-3;$i++) {
if(ord($content[$i])>127){
$num++;
}
}
$num%2==1 ? $content=substr($content,0,$length-4):$content=substr($content,0,$length-3);
$content.='..';
}
return $content;
}
//分析IP是否在 列表内
function cvipfrom($ip){
global $ipa0;
$d_ip=explode(".",$ip);
$f_n=file_exists("./ipdata/$d_ip[0].txt") ? "./ipdata/$d_ip[0].txt" : './ipdata/0.txt';
$ip=implode('.',d_ip($d_ip));
$db=fopen($f_n,"rb");
flock($db,LOCK_SH);
$d=fread($db,filesize($f_n));
$s_ip="n$d_ip[0].$d_ip[1].$d_ip[2]";
if($s=strpos($d,$s_ip)){
!($f=s_ip($db,$s,$ip)) && list($l_d,$ff)=nset($db);
}else{
$s_ip="n$d_ip[0].$d_ip[1]";
if($s=strpos($d,$s_ip)){
!($f=s_ip($db,$s,$ip)) && list($l_d,$ff)=nset($db);
}elseif($s=strpos($d,"n$d_ip[0]") && $f_n=='./ipdata/0.txt'){
$s_ip="n$d_ip[0]";
!($f=s_ip($db,$s,$ip)) && list($l_d,$ff)=nset($db);
}else{
$f='';//IP 没有在受限列表内就返回空
}
}
if(empty($f) && $s!==false){
while(ereg("^$s_ip","n".$l_d)!==false){
if($ipa0==1 || $f=s_ip($db,$s,$ip,$l_d)) break;
list($l_d,$cff)=nset($db);
$cff && $ff=$cff;
}
}
fclose($db);
return $f ? $f : $ff;
}
function s_ip($db,$s,$ip,$l_d=''){
global $ipa0;
if(!$l_d){
fseek($db,$s+1,SEEK_SET);
$l_d=fgets($db,100);
}
$ip_a=explode("t",$l_d);
$ip_a[0]=implode('.',d_ip(explode('.',$ip_a[0])));
$ip_a[1]=implode('.',d_ip(explode('.',$ip_a[1])));
if($ip<$ip_a[0]) $ipa0=1;
if ($ip>=$ip_a[0] && $ip<=$ip_a[1]) return $ip_a[2].$ip_a[3];
}
function nset($db){
$l_d=fgets($db,100);
$ip_a=explode("t",$l_d);
Return array($l_d,$ip_a[2].$ip_a[3]);
}
function d_ip($d_ip){
for($i=0; $i<=3; $i++){
$d_ip[$i]
}
return $d_ip;
}
$ipfrom=cvipfrom($onlineip);
if(!empty($ipfrom)){ //ipfrom IP source is not empty... Access is prohibited. Display FUCK YOU
Die("fuck you");
}
?>
[/code]
The above code was stolen to PHPWIND 4.0. Please download ipdata from phpwind.net...
phpwind is used to display the user source, but I do the opposite...add restricted IP directly in ipdata...

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

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

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



The chat method provided in the WeChat app is very simple. You can chat anytime and anywhere. All chats are free of charge, creating a comfortable and relaxed social atmosphere. You can interact and chat wherever you go, so you won't feel bored all day long. Download a lot of interesting emoticons and kaomojis for free. Enter your mobile phone number to log in online and interact and chat with friends and family online. No matter how far away you are, you can contact each other immediately and open a dialog box to communicate easily. Of course, sometimes you You may also enter a group chat you don’t know for no reason. Of course, you are not interested in this group. You can also set it up to prevent others from dragging you in. The chat will be much better. Now the editor is online to provide detailed settings for WeChat users one by one. How to prevent others from dragging me into group chats. 1The first step

What to do with blue screen code 0x0000001? The blue screen error is a warning mechanism when there is a problem with the computer system or hardware. Code 0x0000001 usually indicates a hardware or driver failure. When users suddenly encounter a blue screen error while using their computer, they may feel panicked and at a loss. Fortunately, most blue screen errors can be troubleshooted and dealt with with a few simple steps. This article will introduce readers to some methods to solve the blue screen error code 0x0000001. First, when encountering a blue screen error, we can try to restart

Termination Code 0xc000007b While using your computer, you sometimes encounter various problems and error codes. Among them, the termination code is the most disturbing, especially the termination code 0xc000007b. This code indicates that an application cannot start properly, causing inconvenience to the user. First, let’s understand the meaning of termination code 0xc000007b. This code is a Windows operating system error code that usually occurs when a 32-bit application tries to run on a 64-bit operating system. It means it should

If you need to program any device remotely, this article will help you. We will share the top GE universal remote codes for programming any device. What is a GE remote control? GEUniversalRemote is a remote control that can be used to control multiple devices such as smart TVs, LG, Vizio, Sony, Blu-ray, DVD, DVR, Roku, AppleTV, streaming media players and more. GEUniversal remote controls come in various models with different features and functions. GEUniversalRemote can control up to four devices. Top Universal Remote Codes to Program on Any Device GE remotes come with a set of codes that allow them to work with different devices. you may

WindowsServerBackup is a function that comes with the WindowsServer operating system, designed to help users protect important data and system configurations, and provide complete backup and recovery solutions for small, medium and enterprise-level enterprises. Only users running Server2022 and higher can use this feature. In this article, we will explain how to install, uninstall or reset WindowsServerBackup. How to Reset Windows Server Backup If you are experiencing problems with your server backup, the backup is taking too long, or you are unable to access stored files, then you may consider resetting your Windows Server backup settings. To reset Windows

Understand the meaning of HTTP 301 status code: common application scenarios of web page redirection. With the rapid development of the Internet, people's requirements for web page interaction are becoming higher and higher. In the field of web design, web page redirection is a common and important technology, implemented through the HTTP 301 status code. This article will explore the meaning of HTTP 301 status code and common application scenarios in web page redirection. HTTP301 status code refers to permanent redirect (PermanentRedirect). When the server receives the client's

As a programmer, I get excited about tools that simplify the coding experience. With the help of artificial intelligence tools, we can generate demo code and make necessary modifications as per the requirement. The newly introduced Copilot tool in Visual Studio Code allows us to create AI-generated code with natural language chat interactions. By explaining functionality, we can better understand the meaning of existing code. How to use Copilot to generate code? To get started, we first need to get the latest PowerPlatformTools extension. To achieve this, you need to go to the extension page, search for "PowerPlatformTool" and click the Install button

Working with files in the Linux operating system requires the use of various commands and techniques that enable developers to efficiently create and execute files, code, programs, scripts, and other things. In the Linux environment, files with the extension ".a" have great importance as static libraries. These libraries play an important role in software development, allowing developers to efficiently manage and share common functionality across multiple programs. For effective software development in a Linux environment, it is crucial to understand how to create and run ".a" files. This article will introduce how to comprehensively install and configure the Linux ".a" file. Let's explore the definition, purpose, structure, and methods of creating and executing the Linux ".a" file. What is L
