On 20-Sep-2001 Felix wrote:
> Hello all
>
> Can anyone suggest their best idea for a way to store IP addresses in a
> MySQL Database?
>
INT UNSIGNED
and use the MySQL functions INET_ATON() & INET_NTOA() for converting.
If you're on a pre-3.23 MySQL server then:
// Convert IP string (XXX.YYY.WWW.ZZZ) to float and back
function inet_aton($a) {
$inet = 0.0;
// $a=preg_replace('/^[0-9a-f:]*:/', '', $a); // eat IPv6 off the front
$t = explode('.', $a);
while (list(,$i) = each($t)) {
$inet *= 256.0;
$inet += $i;
};
return $inet;
}
function inet_ntoa($n) {
$t=array(0,0,0,0);
$msk = 16777216.0;
$n += 0.0;
if ($n < 1)
return(' ');
for ($i = 0; $i < 4; $i++) {
$k = (int) ($n / $msk);
$n -= $msk * $k;
$t[$i]= $k;
$msk /=256.0;
};
$a=join('.', $t);
return($a);
}
Regards,
--
Don Read [EMAIL PROTECTED]
-- It's always darkest before the dawn. So if you are going to
steal the neighbor's newspaper, that's the time to do it.
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]