Skip to content

Instantly share code, notes, and snippets.

@fhefh2015
Created March 8, 2016 08:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save fhefh2015/be05ec87302ab93c8ef1 to your computer and use it in GitHub Desktop.
Save fhefh2015/be05ec87302ab93c8ef1 to your computer and use it in GitHub Desktop.
阻止多个ip访问网站
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