This may not be the right place for this question, please point me at the correct SE site if not.
The PHP Documentation for the function ip2long
states:
Note
Because PHP's integer type is signed, many IP addresses will result in negative integers on 32-bit architectures
Which is fine, however I am little confused if the version of PHP makes a difference?
I am running 64bit Server 2008 with 32bit PHP installed, and I am getting negative integers with some IP addresses. I am clearly running on a 64bit architecture, so this shouldn't be the case according to the (admittedly very vague) documention.
I can only assume that it's because I am running 32bit PHP?? But I can't confirm this anywhere.
You are correct that it is because you are running a 32-bit build of PHP. Since it is compiled as a 32-bit application, despite running on a 64-bit system you still do not get 64-bit integers.
It should also be noted that at the time of writing 64-bit builds of PHP on Windows do not provide 64-bit integers (or large file support) so even if you go with a 64-bit version you will still experience integer overflow.
You can try using
sprintf
with the%u
format to try to get a string representation of the 64-bit number. I used this code with older PHP4 applications running on 32-bit where I wanted to print out a 64-bit integer. Note that it may not be suitable if you need to do anything other than output the 64-bit number.