Home > Backend Development > PHP Problem > How to ban ip access in php

How to ban ip access in php

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

php methods to prohibit IP access: 1. Use the "<?php include("banIP.php");?> method to prohibit access to a certain IP or IP address range; 2. Disable it through the die method A single IP is enough.

How to ban ip access in php

The operating environment of this tutorial: Windows 7 system, PHP version 5.6. This method is suitable for all brands of computers.

Recommended: "PHP Video Tutorial"

php method to prohibit access to a certain ip or ip address range

<?php include("banIP.php");?>
Copy after login

Disable a single ip as follows:

<?php 
//禁用ip地址 
$ip=$_SERVER["REMOTE_ADDR"]; 
$ban=file_get_contents("ban.dat"); 
if(stripos($ban,$ip)) 
{ 
  die("Your IP Address is:$ip,you&#39;re forbiden to view this page!");   
} 
echo "Your IP Address is:$ip,hello!"; 
?>
Copy after login
rrree

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

Related labels:
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