Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Go Back   Code Forums > Application and Web Development > PHP
User Name
Password

Reply
 
LinkBack Thread Tools Display Modes
Old 03-12-2008, 09:29 PM   #1 (permalink)
noobnewbie
Recruit
 
Join Date: Mar 2008
Posts: 1
noobnewbie is on a distinguished road
Exclamation Block IPs and Allow IPs - PHP

Hi ... I'm trying to write a code to allow only 1 IP range and 1 IP address in and ban the rest out. I've got so it bans all the IP's out... but I'm a stuck now... the IP range I want to allow is '150.208.193.*' and '179.155.3.2'

Any help and input would be much appreciated...

Thanks in advanced....

my code so far is :

<?php

//
//$valid_ips[] = '150.208.193.*';
//$valid_ips[] = '179.155.3.2';

$banned_ip[] = '*.*.*.*';

function is_banned($ip)
{ $pattern = str_replace(array('*', '.'), array('\d+', '\.'), $ip);
return preg_match("~^{$pattern}$~", $_SERVER['REMOTE_ADDR']);
}
if (array_filter($banned_ip, 'is_banned'))
{
echo 'Banned';
exit();
}
else
{
echo 'Not banned';
exit();
}
__________________
noobnewbie is offline   Reply With Quote
Old 03-12-2008, 10:53 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,397
sde is on a distinguished road
check out this thread. if you have any questions, post them. make sure you go through the whole thread.. there's different ways to approach it.

PHP ban IP range script
__________________
testing 1 2 3
sde is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -8. The time now is 02:51 AM.


Powered by vBulletin Version 3.6.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2006, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting
Open Circle