homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Gold Sponsor 2015!
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

IPs in array
Add more IPs

Msg#: 4427502 posted 11:51 am on Mar 10, 2012 (gmt 0)

I found a code to block an IP range but don't know how to add more IPs. What I want is to be able to ad multiple IP ranges. Thank you

$range_start = ip2long("");
$range_end = ip2long("61.181.255");
$ip = ip2long($_SERVER['REMOTE_ADDR']);
if ($ip >= $range_start && $ip <= $range_end) {
// blocked



WebmasterWorld Senior Member 10+ Year Member

Msg#: 4427502 posted 6:20 pm on Mar 10, 2012 (gmt 0)

What you have isn't really the best solution for blocking IPs, but it isn't the worst either... the following will make it possible to add more IPs to be blocked:

$blocklist = array(
'', // Single IP
array('','61.181.255'), // IP Range
'' // Another single IP
$ip = ip2long($_SERVER['REMOTE_ADDR']);
foreach ($blocklist as $b) {
if (is_array($b)) {
$s = ip2long($b[0]);
$e = ip2long($b[1]);
if ($ip >= $s && $ip <= $e) {
print 'Blocked IP'; exit();
elseif ($ip == ip2long($b)) {
print 'Blocked IP'; exit();


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved