Login   Register  
PHP Classes
elePHPant
Icontem

fix a bu in a script

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us

      Top level forums  >  PHP Specialists  >  General  >  fix a bu in a script  
Subject:fix a bu in a script
Summary:preg_match function bug
Messages:1
Author:amin
Date:2012-09-16 20:45:23
Update:2012-09-17 00:43:05
 

  1. fix a bu in a script   Reply   Report abuse  
Picture of amin
amin
2012-09-17 00:43:05
hello there

i have searched for a ip range ban scripted and i have found this script


$userIP = ''; // User ip here either by $_SERVER['REMOTE_ADDR'] or with the getUserIP() function
$blockedAddresses = array('192.182.127.12', '255.0.0.0', '127.0.0.1', '192.*.*.*');
// Check every ip address
if(is_array($blockedAddresses) && count($blockedAddresses)) {
if(in_array($userIP, $blockedAddresses)) {
// this is for exact matches of IP address in array
header('Location: http://google.com');
exit();
} else {
// this is for wild card matches
foreach($blockedAddresses as $ip) {
if(preg_match('~'.$ip.'~', $userIP)) {
header('Location: http://google.com');
exit();
}
}
}
}

in this line
$blockedAddresses = array('192.182.127.12', '255.0.0.0', '127.0.0.1', '192.*.*.*');

if you put 7.*.*.*

every ip address that contains 7 will be blocked such as 127.0.0.1


is there anyone that knows about the bug?

with prior thanks