PHP MySQL find IP address (between) stored IP address ranges
Hi,
I am wondering how to code a PHP MySQL 'SQL' query to find the given IP address between 2 stored IP address ranges.
I am trying this:
$theIp = 'xxx.xxx.xxx.xxx';
$result = mysqli_query($link,"SELECT * FROM `ipAddresses` WHERE `start` <= '$theIp' AND `end` >= '$theIp'") or die(mysql_error());
But it doesn't seem to be working correctly. Should i store the IP data differently? Not in one field.
in php you can use ip2long function:
ip2long
http://php.net/manual/en/function.ip2long.php
in MySQL, use INET_ATON:
https://dev.mysql.com/doc/refman/5.0/en/miscellaneous-functions.html#function_inet-aton