I am building an admin panel. and I want to block certain IP ranges. I’m testing this on my localhost wamp server but ir doesn’t seem to redirect me.
<?php
if($_SERVER['REMOTE_ADDR'] == '127.0.0..*')
header("Location: http://google.com");
else
echo "Hai";
?>
Any input is appreciated.
Is sufficient to use string comparison
Update: Taken from the comments of inits answer
Then just make the same string comparison against this block
If you want to test the remote address against both blocks at once, you will probably put them together into one expression. This time we need a different approach
The
substr()-part takes the IP until the last.. We can just try to find this string in a set (-> array) of IP-prefixes.