How to get client IP address in Laravel 5+

前端 未结 18 2700
你的背包
你的背包 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:06

    Use request()->ip().

    From what I understand, since Laravel 5 it's advised/good practice to use the global functions like:

    response()->json($v);
    view('path.to.blade');
    redirect();
    route();
    cookie();
    

    And, if anything, when using the functions instead of the static notation my IDE doesn't light up like a Christmas tree.

提交回复
热议问题