Click here to get back home

Function to tell if IP address is in a range

 HomeNewsGroups | Search | About
 comp.lang.php    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Function to tell if IP address is in a range axlq 07-05-2008
Posted by axlq on July 5, 2008, 2:40 pm
Please log in for more thread options

After failing to find this in my searches, I thought I'd ask
here: Is there a php function that can tell me if an IP address
falls within a range?

Something like this:

$result = is_in_ip_range($_SERVER['REMOTE_ADDR'], '78.157.128.0/19');

I need this for denying access to my web contact form from certain IP
ranges.

I can write my own, but wondered if there's something in the massive
php function library that I overlooked.

-A

Posted by C. (http://symcbean.blogspot.c on July 6, 2008, 6:53 am
Please log in for more thread options
On Jul 5, 7:40 pm, a...@spamcop.net (axlq) wrote:
> After failing to find this in my searches, I thought I'd ask
> here: Is there a php function that can tell me if an IP address
> falls within a range?
>
> Something like this:
>
> $result = is_in_ip_range($_SERVER['REMOTE_ADDR'], '78.157.128.0/19');
>
> I need this for denying access to my web contact form from certain IP
> ranges.
>
> I can write my own, but wondered if there's something in the massive
> php function library that I overlooked.
>
> -A

There's a PEAR class - Net_IPv4. There are probably other
implementations too - try phpclasses, freshmeat or google.

C.

Posted by Betikci Boris on July 6, 2008, 7:14 am
Please log in for more thread options
On Jul 5, 9:40 pm, a...@spamcop.net (axlq) wrote:
> After failing to find this in my searches, I thought I'd ask
> here: Is there a php function that can tell me if an IP address
> falls within a range?
>
> Something like this:
>
> $result = is_in_ip_range($_SERVER['REMOTE_ADDR'], '78.157.128.0/19');
>
> I need this for denying access to my web contact form from certain IP
> ranges.
>
> I can write my own, but wondered if there's something in the massive
> php function library that I overlooked.
>
> -A

You need to use string manipulation functions to process second
parameter, however your
Function parameters should be like this:
ip_func($_SERVER['REMOTE_ADDR'],<IP TO START>,<IP TO STOP>);

Ex. ip_func($_SERVER['REMOTE_ADDR'] , 78.157.128.0 , 78.157.128.255 );

Posted by axlq on July 6, 2008, 11:34 am
Please log in for more thread options
>On Jul 5, 9:40 pm, a...@spamcop.net (axlq) wrote:
>> After failing to find this in my searches, I thought I'd ask
>> here: Is there a php function that can tell me if an IP address
>> falls within a range?

>Function parameters should be like this:
>ip_func($_SERVER['REMOTE_ADDR'],<IP TO START>,<IP TO STOP>);
>
>Ex. ip_func($_SERVER['REMOTE_ADDR'] , 78.157.128.0 , 78.157.128.255 );

Oh, that's right. If I passed the second two arguments as strings,
I could simply use lexical comparison to determine if the first
argument is between them.

Thanks.
-A

Posted by Jerry Stuckle on July 6, 2008, 3:09 pm
Please log in for more thread options
axlq wrote:
>> On Jul 5, 9:40 pm, a...@spamcop.net (axlq) wrote:
>>> After failing to find this in my searches, I thought I'd ask
>>> here: Is there a php function that can tell me if an IP address
>>> falls within a range?
>
>> Function parameters should be like this:
>> ip_func($_SERVER['REMOTE_ADDR'],<IP TO START>,<IP TO STOP>);
>>
>> Ex. ip_func($_SERVER['REMOTE_ADDR'] , 78.157.128.0 , 78.157.128.255 );
>
> Oh, that's right. If I passed the second two arguments as strings,
> I could simply use lexical comparison to determine if the first
> argument is between them.
>
> Thanks.
> -A
>

Is 101.01.01.01 within the range of 98.98.98.98 and 110.110.110.110?
Passed as a string, it is not.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================


Similar ThreadsPosted
address of function or a virtual function August 16, 2007, 11:00 am
mail() function error: (SMTP server response: 501 5.5.4 Invalid Address) May 11, 2008, 12:53 pm
Iron Range Area of MN, USA April 8, 2005, 2:11 pm
How to implement range header in PHP??? August 30, 2006, 9:31 am
selectbox dynamic range options August 14, 2007, 7:01 pm
Retrieving array values by range of keys October 15, 2007, 9:09 am
Calculating week range from specific date - Any functions? May 6, 2005, 6:44 pm
JPGraph - setting Y axis range and calculating left margin width? February 23, 2007, 2:19 pm
Broadband in telecommunications is a term that refers to a signaling method that includes or handles a relatively wide range of frequencies... March 20, 2008, 5:04 am
Using MySQL, can I SELECT rows only within a certain range (ie. rows 11-20) July 31, 2006, 9:03 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap