Script assistance, IP address related

Hi, could someone please show me in PHP how to express a low and high
IP address, and do something based on result?

Like

<?

$start_ip_range = "202.100.100.100"
$end_ip_range = "220.255.255.255"

if $actual_ip_address between $start_ip_range and $end_ip_range
{
do something
}

?>
endlesstide [ Fr, 09 Februar 2007 04:23 ] [ ID #1624461 ]

Re: Script assistance, IP address related

On Feb 9, 4:23 am, endlesst... [at] gmail.com wrote:
> Hi, could someone please show me in PHP how to express a low and high
> IP address, and do something based on result?
>
> Like
>
> <?
>
> $start_ip_range = "202.100.100.100"
> $end_ip_range = "220.255.255.255"
>
> if $actual_ip_address between $start_ip_range and $end_ip_range
> {
> do something
>
> }
>
> ?>

Dear endless,

split your ip addresses (start_ip, end_ip, and actual_ip) into its
parts (e.g. with explode) and compare them.

Or create a hex representation of your addresses and compare them.

Or just remove the dots and compare the results.

Or just google to find a script ready to do that ;)

Good luck

------------------------------------------------
online accounting on bash bases
Online Einnahmen-Ausgaben-Rechnung
http://www.ea-geier.at
------------------------------------------------
m2m server software gmbh
http://www.m2m.at
m2m tech [ Fr, 09 Februar 2007 07:23 ] [ ID #1624463 ]

Re: Script assistance, IP address related

> Or just remove the dots and compare the results.
>
> Or just google to find a script ready to do that ;)
>

Honestly, why search Google for two lines of code? ;-)

str_replace(".","",$ip);
if ($min < $ip && $ip<$max) ...


--
Christoph Burschka
Christoph Burschka [ Fr, 09 Februar 2007 07:45 ] [ ID #1624464 ]

Re: Script assistance, IP address related

endlesstide [at] gmail.com wrote:

> Hi, could someone please show me in PHP how to express a low and high
> IP address, and do something based on result?
>
> Like
>
> <?
>
> $start_ip_range = "202.100.100.100"
> $end_ip_range = "220.255.255.255"
>
> if $actual_ip_address between $start_ip_range and $end_ip_range
> {
> do something
> }
>
> ?>

I believe you're looking for something like this:

<?php
$start_ip = ip2long($start_ip_range);
$end_ip = ip2long($end_ip_range);
$user_ip = ip2long($_SERVER["REMOTE_ADDR"]);

if (($user_ip >= $start_ip) and ($user_ip <= $end_ip)) {
// do something
}
?>

--
Kim André Akerĝ
- kimandre [at] NOSPAMbetadome.com
(remove NOSPAM to contact me directly)
kimandre [ Fr, 09 Februar 2007 09:47 ] [ ID #1624465 ]
PHP » alt.php » Script assistance, IP address related

Vorheriges Thema: sending encrypted emails
Nächstes Thema: command-line php displays code instead of executing code