note 97982 modified in function.ip2long by visualmind

From: Date: Wed, 19 May 2010 11:40:31 +0000
Subject: note 97982 modified in function.ip2long by visualmind
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169406@lists.php.net to get a copy of this message
I would just like to try and clear up simply that if storing IPV4 addresses in an SQL database you should use an unsigned int (4 bytes). The easiest way to do this in PHP is to use sprintf(): <?php $dottedFormatAddress = '127.0.0.1'; $ipv4address = sprintf("%u", ip2long($dottedFormatAddress)); ?> Primary reasons are it's compatible with database functions like MySQL's INET_ATON & INET_NTOA (which also use unsigned int's), it's efficient, and it's the most common format used by IP lookup databases. --was-- I would just like to try and clear up simply that if storing IPV4 addresses in an SQL database you should use an unsigned int (4 bytes). The easiest way to do this in PHP is to use sprintf(): $dottedFormatAddress = '127.0.0.1'; $ipv4address = sprintf("%u", ip2long($dottedFormatAddress)); Primary reasons are it's compatible with database functions like MySQL's INET_ATON & INET_NTOA (which also use unsigned int's), it's efficient, and it's the most common format used by IP lookup databases. http://php.net/manual/en/function.ip2long.php

« previous php.notes (#169406) next »