note 113080 added to function.ip2long
| From: | rasmus at mindplay dot dk | Date: | Tue, 27 Aug 2013 14:55:00 +0000 |
| Subject: | note 113080 added to function.ip2long | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-196095@lists.php.net to get a copy of this message | ||
As pointed out by others, this function's return value is not consistent on 32 and 64-bit
platforms.
Your best bet for consistent behavior across 32/64-bit platforms (and Windows) is the lowest common
denominator: force the return value of ip2long() into a signed 32-bit integer, e.g.:
var_dump(unpack('l', pack('l', ip2long('255.255.255.0'))));
This looks idiotic, but it gives you a consistent signed integer value on all platforms.
(the arguments to both pack() and unpack() are the lower-case letter "L", not the number
"1", in case it looks that way on your screen...)
----
Server IP: 64.71.164.2
Probable Submitter: 68.70.61.119
----
Manual Page -- http://php.net/manual/en/function.ip2long.php
Edit -- https://master.php.net/note/edit/113080
Del: integrated -- https://master.php.net/note/delete/113080/integrated
Del: useless -- https://master.php.net/note/delete/113080/useless
Del: bad code -- https://master.php.net/note/delete/113080/bad+code
Del: spam -- https://master.php.net/note/delete/113080/spam
Del: non-english -- https://master.php.net/note/delete/113080/non-english
Del: in docs -- https://master.php.net/note/delete/113080/in+docs
Del: other reasons-- https://master.php.net/note/delete/113080
Reject -- https://master.php.net/note/reject/113080
Search -- https://master.php.net/manage/user-notes.php