|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2001-12-07 08:32 UTC] sterling@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 01:00:01 2025 UTC |
Actually the my fix for this problem is on the PHP side, not in the PHP-code it self: function jk_ip2long ($ip) { preg_match("#^([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})\.([0-9]{1,3})$#", $ip, $a); $long = $a[1] << 24 | $a[2] << 16 | $a[3] << 8 | $a[4] << 0; ## handling negative urls if($long < 0) $long += pow(2,32); return $long; } ## long2ip function jk_long2ip ($long) { ## handle long value which should be signed in PHP but are unsigned if ($long > 0x7fffffff) { ## although this code seems to be useless, it does what we want $l = ($long - 0x7fffffff) - 1; $long = -(0x7fffffff - $l) - 1; } $ip3 = sprintf("%d.%d.%d.%d", $long >> 24 & 0xff, $long >> 16 & 0xff, $long >> 8 & 0xff, $long >> 0 & 0xff ); return $ip3; } You can see a working example at http://jan.kneschke.de/projects/phpbugs/ip2long.php