朱纯树博客
VPS测评推荐网站
cloudacead cloudacead

Laravel获取客户端IP方法

自定义函数

function GetClientIp()
    {
        if (getenv('HTTP_CLIENT_IP')) {
            $ip = getenv('HTTP_CLIENT_IP');
        }
        if (getenv('HTTP_X_REAL_IP')) {
            $ip = getenv('HTTP_X_REAL_IP');
        } elseif (getenv('HTTP_X_FORWARDED_FOR')) {
            $ip = getenv('HTTP_X_FORWARDED_FOR');
            $ips = explode(',', $ip);
            $ip = $ips[0];
        } elseif (getenv('REMOTE_ADDR')) {
            $ip = getenv('REMOTE_ADDR');
        } else {
            $ip = '0.0.0.0';
        }

        return $ip;
    }

最简单的方法

$request->getClientIp()

赞(2) 打赏
未经允许不得转载:VPS测评推荐网站 - 朱纯树博客 » Laravel获取客户端IP方法

评论 190

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址
  1. #195

    neurontin 600 mg pill medication neurontin 300 mg

    Isiahrep8小时前回复
  2. #194

    п»їcipro generic antibiotics cipro

    JefferyPap9小时前回复
  3. #193

    viagra video how to get cialis in australia cialis high blood pressure side effect how long after taking cialis can i take viagra

  4. #192
  5. #191

    neurontin capsules neurontin 100 mg cap

    JefferyPap2天前回复
  6. #190
  7. #189

    order losartan 50mg without prescription – cozaar medication promethazine order online

  8. #188

    buy diflucan pill diflucan 100 mg tablet

    Isiahrep3天前回复
  9. #187

    https://gabapentin.icu/# neurontin brand name in india

    Georgevop3天前回复
  10. #186

    https://buymetformin.best/# metformin hcl 500 mg

    Ronaldimamy3天前回复