-->

How to get the server IP with Laravel

2020-07-05 07:04发布

问题:

Using Laravel, I can get the client IP with request()->ip().

Is there a Laravel built-in way to get the server IP? Or is it something "impossible" (same problem as SERVER_ADDRreliability)

回答1:

You can use request object:

request()->server('SERVER_ADDR');

Or you can use standard PHP way:

$_SERVER['SERVER_ADDR'];


回答2:

Request::server('SERVER_ADDR') :)

URL Reference: https://laravel.com/api/5.3/Illuminate/Http/Request.html



回答3:

$_SERVER['SERVER_ADDR']; for server ip
$_SERVER['SERVER_PORT']; for server port


标签: laravel