Login   Register  
PHP Classes

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
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
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.*.*.*');
// 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');
} else {
// this is for wild card matches
foreach($blockedAddresses as $ip) {
if(preg_match('~'.$ip.'~', $userIP)) {
header('Location: http://google.com');

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

if you put 7.*.*.*

every ip address that contains 7 will be blocked such as

is there anyone that knows about the bug?

with prior thanks