Questions tagged [ip2long]

Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address

Converts a string containing an (IPv4) Internet Protocol dotted address into a proper address

https://www.php.net/manual/en/function.ip2long.php

12 questions
4
votes
1 answer

ip2long("012.012.012.012") returns false on Linux

Suppose there are leading zeros in IPv4 address representation such as 012.012.012.012. To suppress the leading zeros, I simply write the following code, and it works as I expected on my Mac: % php -r…
ernix
  • 3,442
  • 1
  • 17
  • 23
2
votes
0 answers

Can you help me understand why my last ip2long is empty?

I've been fighting for hours ... i want to understand if my ip is included in a list of ip ranges. The list comes from a file, I do a foreach and an if if(ip2long($_SERVER['REMOTE_ADDR']) >= ip2long($start) && ip2long($_SERVER['REMOTE_ADDR']) <=…
alebal
  • 5,838
  • 3
  • 10
  • 28
2
votes
2 answers

How to do wildcard search for IP addresses using INET_ATON in MySQL?

I found this method to store IP addresses in MySQL database as integer using INET_ATON: https://stackoverflow.com/a/5133610/4491952 Since IPv4 addresses are 4 byte long, you could use an INT (UNSIGNED) that has exactly 4 bytes: `ipv4` INT…
Trondro Mulligan
  • 485
  • 3
  • 19
2
votes
2 answers

IP range comparison using ip2long

I am trying to compage an IP using ip2long as described in this tutorial: How to check an IP address is within a range of two IPs in PHP? The code is as follows: $ip2 = ip2long("127.0.0.1"); $high_ip = ip2long("128.0.0.0"); $low_ip =…
user1721135
  • 6,864
  • 8
  • 34
  • 63
0
votes
1 answer

PHP Calculate Long Integer Range of Subnet ip2long

I am trying to determine whether a website visitor came from an EU country, and if so show them a cookie consent banner per their law. I downloaded a table listing IPv4 of all EU countries (ie: 1.178.224.0/19) and uploaded it to mySQL. There are…
Bill Demaria
  • 71
  • 2
  • 10
0
votes
0 answers

How can i convert IPv6 to long like we do for IPv4 using ip2long?

I have IP database for a certain country. I have paid version of Ip2Lcoation and i got all the IPv6 ranges and IPv4. In my web app I am converting all the IPs to long using ip2long function. It works perfectly with IPv4 but with IPv6 it fails? i…
kool_Coder
  • 149
  • 1
  • 12
0
votes
0 answers

Function ip2long fails in class

When I use the ip2long function in a class, it does not return a valid result. If I call the function outside of the class, as shown, it returns a valid result. But if I use the class, the conversion is ignored. So I assume the problem is with the…
user3052443
  • 758
  • 1
  • 7
  • 22
0
votes
0 answers

Calculate +1 ip address from ip address

I am using ip2long to calculate the subnet address, broadcast address, and wildcard mask and It´s works but I need to calculate +1 ip address from an specific ip address for example 10.10.10.7 I need to sum +1 ip address and get 10.10.10.8 I am…
htmlpower
  • 169
  • 1
  • 16
0
votes
3 answers

How can I simplify an IP address using PHP? Trying long2ip(ip2long(address))

My system includes a third party box that stores IP addresses and compares them to values sent from my Web interface. I have a problem that a user entered the netmask for the third party box as 255.255.255.000, and the box stored it as…
Sinc
  • 553
  • 1
  • 8
  • 31
0
votes
1 answer

long2ip is not working with string from database

I have a problem with the long2ip function. With data from $_SERVEUR or a string var it's working fine, giving me the correct IP. But with a string from the database the result is 0.0.0.0 .
0
votes
2 answers

Can't get ip2long() to work

I'm trying to compare some IP addresses that are stored as strings. I read about ip2long() to convert the string to an integer so I'm playing around with it to see if it would do what I want. So, initially, I'm just trying to see what the converted…
ChessDad
  • 45
  • 6
0
votes
1 answer

How to store ip2long negative value on a 32 bit system to MySQL

I have to store an IP address into a MySQL table running on a 32 bit system. On a 64 bit system I would simply use INT(10) UNSIGNED since ip2long will always be an absolute value. How to make it work on 32 bit? I have two options. Remove UNSIGNED…
Aley
  • 8,540
  • 7
  • 43
  • 56