如何检查一个IP地址是否在PHP中的两个IP范围内?

2022-01-24 00:00:00 range ip php

我有一个 IP 地址,并获得了另外两个 IP 地址,它们共同创建了一个 IP 范围.我想检查第一个 IP 地址是否在此范围内.我如何在 PHP 中找到它?

I have an IP address and I'm given two other IP addresses which together creates an IP range. I want to check if the first IP address is within this range. How can i find that out in PHP?

推荐答案

With ip2long() 很容易将您的地址转换为数字.在此之后,您只需检查数字是否在范围内:

With ip2long() it's easy to convert your addresses to numbers. After this, you just have to check if the number is in range:

if ($ip <= $high_ip && $low_ip <= $ip) {
  echo "in range";
}

相关文章