//检查白名单ip
    private function _checkAllowIp()
    {
        $allowIp = ['203.195.156.12'];
        $ip = $this->getIp();
        if (!in_array($ip, $allowIp)) {
            exit();
        }
    }

    /**
     * 获取客户端访问ip
     */
    private function getIp()
    {
        if (getenv('HTTP_CLIENT_IP')) {
            $ip = getenv('HTTP_CLIENT_IP');
        } else if (getenv('HTTP_X_FORWARDED_FOR')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
        } else if (getenv('REMOTE_ADDR')) {
            $ip = getenv('REMOTE_ADDR');
        } else {
            $ip = $_SERVER['REMOTE_ADDR'];
        }
        $ips = explode(',', $ip);
        if (count($ips) > 1) {
            $ip = $ips[0];
        }
        return $ip;
    }

 

相关文章:

  • 2022-03-09
  • 2022-12-23
  • 2021-10-20
  • 2022-12-23
  • 2021-11-19
猜你喜欢
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
  • 2021-06-24
  • 2021-06-21
  • 2021-09-17
相关资源
相似解决方案