note 27212 added to function.ip2long
| From: | daevid at daevid dot com | Date: | Wed, 27 Nov 2002 11:39:57 +0000 |
| Subject: | note 27212 added to function.ip2long | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-40030@lists.php.net to get a copy of this message | ||
I don't think the sprintf or the abs() methods will work because how will you get back the
original IP address? paste this bit of PHP code and see what I mean.
//the range is a signed LONG INT (4 Bytes)
$ip = "192.168.0.5";
echo "IP = ".$ip."<P>";
echo "CORRECT:<BR>";
$long = ip2long($ip);
echo "ip2long() = ".$long."<BR>";
echo "long2ip() = ".long2ip($long)."<P>";
echo "WRONG:<BR>";
$absversion = abs(ip2long($ip));
echo "abs(ip2long()) = ".$absversion."<BR>";
echo "long2ip() = ".long2ip($absversion)."<P>";
echo "WRONG:<BR>";
$sprintversion = sprintf("%u",ip2long($ip));
echo "sprintf %u = ".$sprintversion."<BR>";
echo "long2ip() = ".long2ip($sprintversion)."<BR>";
//FYI: 255.255.255.255 = -1 and 0.0.0.0 = 0
--
http://www.php.net/manual/en/function.ip2long.php
http://master.php.net/manage/user-notes.php?action=edit+27212
http://master.php.net/manage/user-notes.php?action=delete+27212
http://master.php.net/manage/user-notes.php?action=reject+27212