RE: [PHP] Broken ip2long and long2ip?

From: Date: Sun, 20 May 2001 11:58:02 +0000
Subject: RE: [PHP] Broken ip2long and long2ip?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-53606@lists.php.net to get a copy of this message
> From: Sean Cazzell [mailto:cazzell@eng.usf.edu] > Sent: Sunday, May 20, 2001 8:41 AM [...] > It appears that the integer type being used by these functions is not able > to store the entire 32 bits (4 bytes). It can only handle up to 31 bits - > my guess is the type is signed when it should be unsigned. > > In any case,I'm running PHP 4.0.5 on Linux 2.4.3 on an x86 machine. I > would appreciate it if a someone can verify this before I submit it as a > bug. > [...] You're right. Integers are allways signed and therefore 31 Bit. Use this: $ip = '192.168.100.102'; $lo = ip2long($ip); if ($lo < 0) $lo += pow(2,32); $lo does now contain the right value, PHP internally converts the data type to double. BTW, long2ip() accepts both values, a signed integer or a double value. I think this isn't a bug, it is due to the pure type concept of PHP, where no real long-values or bigint (like MySQL) are possible. Put a better type concept on your wishlist for PHP 5. Joerg joerg@krause.net www.php.comzept.de

« previous php.general (#53606) next »