简体   繁体   中英

Calculate IP Between IP range PHP

How do i calculate between Ip Addresses. for Example:

$ip_low_range = '91.0.0.0';
$ip_max_range = '91.23.255.255';
$user_ip  = '91.1.0.0';
in_range($user_ip , $ip_low_range , $ip_max_range,);

in_range() - is the function that i'm looking for.

Thanks!

You could use ip2long:

$ip_low_range = ip2long('91.0.0.0');
$ip_max_range = ip2long('91.23.255.255');
$user_ip  = ip2long('91.1.0.0');
if ($user_ip >= $ip_low_range && $user_ip <= $ip_max_range) {
    echo "in range";
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM