function getIp() {
return "<?php echo $_SERVER['REMOTE_ADDR']; ?>";
}
I want to adapt or redo this so that certain actions can only be taken from localhost or my isp server. I can make it work with a little bit of JavaScript for 127.0.0.1 but not for the other.
Appreciate any help; thanks
You really want to do this completely on the server. If you check for IPs on the client side then people can very easily hack around that. For example by modifying your code in their browser using a web inspector like Firebug.
Fortunately it is pretty simple to do on the server side:
The $_SERVER['REMOTE_ADDR'] variable is a simple string so you should be able to use string comparison to check for the IPs that you want.
Like for example:
<?php
if ($_SERVER['REMOTE_ADDR'] == "127.0.0.1" || $_SERVER['REMOTE_ADDR'] == "1.2.3.4") {
echo "Show secret things here";
}
?>
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