I have a PHP page I need to limit execution access of to only clients inside our firewall.
How would I write a php-script that can look up the clients ip-address and match it to a ip-range (for instance 10...* or 200.10.10.*).
You can use ip2long to convert dotted quads to long values, then just perform some arithmetic to check a given network/mask combination:
$network=ip2long("200.10.10.0");
$mask=ip2long("255.255.255.0");
$remote=ip2long($_SERVER['REMOTE_ADDR']);
if (($remote & $mask) == $network)
{
//match!
}
else
{
//does not match!
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With