|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10924 long2ip gives wrong result/binary arithmatic does not work
Submitted: 2001-05-17 09:24 UTC Modified: 2001-12-07 08:33 UTC
From: richarde at eskom dot co dot za Assigned:
Status: Closed Package: Network related
PHP Version: 4.0.4pl1 OS: Linux Redhat 6.2
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: richarde at eskom dot co dot za
New email:
PHP Version: OS:


 [2001-05-17 09:24 UTC] richarde at eskom dot co dot za
$x = 2473473034;         // in int form
settype($x, "integer");  // this line has no effect on final result of long2ip

echo "long ".is_long($x);
echo "<P>";

$y = ip2long("");
echo "long ".is_long($y);
echo "<P>";

echo ip2long("");  // should be 2473473034
echo "<P>";

echo long2ip($y);               // correct result here
echo "<P>";

echo long2ip($x);               // wrong result
echo "<P>";

echo $y & 127;               // correct result
echo "<P>";

echo $x & 127;               // incorrect result - should be 10
echo "<P>";

**** cut ****

basically there is no way to do ip arithmatic using php - I cannot get large numbers like ip addresses from a database stored as integers and minipulate them - AND, OR and XOR do not work on large number as in example.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2001-05-19 20:43 UTC]
There is no solution for this, because PHP only deals with signed longs.
However, you can now use the %u modifier in printf and sprintf to show a long unsigned number like this:

    printf ("%u\n", ip2long (""));


I suspended this bug, until unsigned longs are really working (there are some feature request for this already).

 [2001-12-07 08:33 UTC]
long2ip is now fixed as well, as it accepts a string value, which is then properly converted to a unsigned long...
PHP Copyright © 2001-2022 The PHP Group
All rights reserved.
Last updated: Mon Jan 17 21:03:35 2022 UTC