Hi everybody, and thanks for a great resource, epsecially Perkiset.
I love the notice that the topic is old, as I am frequently guilty of reviving old threads. However I must do so again

Trying to use this code I may have found an error, or I may be making an error myself. I convert the IP to an integer, and then when I try to convert the integer back to an IP, the last octet is always 255. Is this an error in the code or am I screwing it up somehow? Probably the latter. I am using the code given above by Perkiset, only modified to supply an IP and output results to the browser:
<?php
define('_OCT0', pow(256, 3));
define('_OCT1', pow(256, 2));
define('_OCT2', 256);
function IPtoInt($inStr)
{
if (!preg_match('/([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})/', $inStr, $parts))
throw new Exception("IPtoInt: Invalid IP Address ($inStr)");
return ($parts[1] * _OCT0) + ($parts[2] * _OCT1) + ($parts[3] * _OCT2) + $parts[4];
}
function InttoIP($inInt)
{
$oct4 = $inInt % 256;
$oct4 = ($oct4 < 0) ? 256 + $oct4 : $oct4;
return
(($inInt / _OCT0) % 256) . '.' .
(($inInt / _OCT1) % 256) . '.' .
(($inInt / _OCT2) % 256) . '.' .
$oct4;
}
$ip1 = "206.248.172.160";
echo IPtoInt($ip1)."<br><br>";
//run script to get result of IPtoInt, then insert below
$ip2 = "3472403616";
echo InttoIP($ip2);
?>
So I am using the code as given by Perkiset, except for the echoes I added myself. I run the script once to get the integer from the first function, then insert it into the code, and then run it again to see if i get the original IP back. But the last octet is always 255. Am I doing something wrong or is the code wrong?
I calculated the result of IptoInt manually using a calculator, it seems correct.
The InttoIp I'm not sure of, I'm not familiar with that code at all, particularly "$oct4 = ($oct4 < 0) ? 256 + $oct4 : $oct4;" ... I have no idea what that means. So I'm at a loss there. Not familiar with the "?" or the ":" in this context.
Thanks!