How to get client IP address in Laravel 5+

前端 未结 18 2688
你的背包
你的背包 2020-11-27 11:11

I am trying to get the client\'s IP address in Laravel.

It is easy to get a client\'s IP in PHP by using $_SERVER[\"REMOTE_ADDR\"]. It is working fine

18条回答
  •  失恋的感觉
    2020-11-27 12:05

    If you want client IP and your server is behind aws elb, then user the following code. Tested for laravel 5.3

    $elbSubnet = '172.31.0.0/16';
    Request::setTrustedProxies([$elbSubnet]);
    $clientIp = $request->ip();
    

提交回复
热议问题