You are here: Re: [PHP] function to compare ip addr to a ip range « PHP « IT news, forums, messages
Re: [PHP] function to compare ip addr to a ip range

Posted by tg-php on 10/13/05 18:38

You could try converting to long IP addresses and comparing that way:

<?php

// To actually get the long IP address that you can use in http://
// you sometimes need to use something like printf("%u\n", ip2long($ip));

// See also: http://us3.php.net/manual/en/function.ip2long.php

$startip = "192.168.0.5";
$endip = "192.168.0.16";
$targetip = "192.168.0.7";

$startlong = ip2long($startip);
$endlong = ip2long($endip);
$targetlong = ip2long($targetip);

if ($startlong <= $targetlong AND $targetlong <= $endlong)
echo "within range";
else
echo "out of range";


?>

= = = Original message = = =

Does anyone have a function that will check if an ip address falls with
a starting/ending ip address range>>



Thanks,

Dave


___________________________________________________________
Sent by ePrompter, the premier email notification software.
Free download at http://www.ePrompter.com.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация