Created
March 8, 2016 08:21
-
-
Save fhefh2015/be05ec87302ab93c8ef1 to your computer and use it in GitHub Desktop.
阻止多个ip访问网站
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ( !file_exists('blocked_ips.txt') ) { | |
$deny_ips = array( | |
'127.0.0.1', | |
'192.168.1.1', | |
'83.76.27.9', | |
'192.168.1.163' | |
); | |
} else { | |
$deny_ips = file('blocked_ips.txt'); | |
} | |
// read user ip adress: | |
$ip = isset($_SERVER['REMOTE_ADDR']) ? trim($_SERVER['REMOTE_ADDR']) : ''; | |
// search current IP in $deny_ips array | |
if ( (array_search($ip, $deny_ips))!== FALSE ) { | |
// address is blocked: | |
echo 'Your IP adress ('.$ip.') was blocked!'; | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment