How to get client IP address in Laravel 5+

前端 未结 18 2686
你的背包
你的背包 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 11:56

    If you worry about getting the IP address but do not need or want to use any Laravel functionality, you can use just php:

    PHP < 5.3.0
    $localIP = getHostByName(php_uname('n'));

    PHP >= 5.3.0
    $localIP = getHostByName(getHostName());

    as answered in this thread: PHP how to get local IP of system

提交回复
热议问题