Comparing IP addresses

后端 未结 1 1938
我寻月下人不归
我寻月下人不归 2021-01-21 06:37
function getIp() {
  return \"\";
}

I want to adapt or redo this so that certain actions can only be take

相关标签:
1条回答
  • 2021-01-21 06:50

    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";
       }
    ?>
    
    0 讨论(0)
提交回复
热议问题