I'm trying an IP by using ip2long
as described in this tutorial :
The code is as follows:
$ ip2 = ip2long ("127.0.0.1"); $ High_ip = ip2long ("128.0.0.0"); $ Low_ip = ip2long ("126.0.0.1"); If ($ ip2 & lt; = $ high_ip & amp; $ low_ip & lt; = $ ip2) {resonant in "category"; } Else {resonant "no"; }
I have already tried switching to high and low IP and still get the same result.
Why is my script not known that the IP is actually the range?
Note: I need to compare with the detailed categories compared to the user's ID: 1.1.2.0 - 1.2.2.0.
You must use sprintf ("% u", $ ip)
("% U", $ ip) & lt; = Sprintf ("% u", $ high_ip) & amp; Sprintf ("% u", if it is:
$ Low_ip) & lt; = Sprintf ("% u", $ ip))
Why? If you are looking into the manual:
Why you will see it:
Note: Because
, and many IP addresses result in negative integer on 32-bit architecture , you use sprintf () or "% u" formatter of printf () is required. To represent the strings of unsigned IP addresses.
Edit:
As:
Good to know, but what's the reason Is it working properly? Because it can not be 32-bit architecture? - briosheje 12 minutes ago
Yes ^ This works in online IDE, as it is a 64 bit architecture. And as mentioned above in the quote on 32-bit architecture, this will not work because it results in negative intervals, so you have to use % u
+ sprintf () Code> or
printf ()
.
What architecture do I have?
All you can do is:
echo PHP_INT_MAX;
2147483647 - & gt; 32 bit 9223372036854775807 - & gt; 64 bit
Edit 2:
Also:
BTW I use XMPP I am, but in this case it will not make any difference? - user1721135 22 minutes ago
PHP 64 bits does not support Windows or at least not official. You can view / read it here:
And a quote from there:
x86_64 builds x64 Builds PHP for Windows Should be experimental in question , and yet does not provide 64-bit integer or large file support. Please see this post for the ongoing work to improve these builds.
And if you are not using XMPP on the windows, then you can download XMPP Mac and For Linux here with 64 bit PHP:
No comments:
Post a Comment