如何使用 Laravel 获取服务器 IP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41258208/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to get the server IP with Laravel
提问by rap-2-h
Using Laravel, I can get the client IP with request()->ip()
.
使用 Laravel,我可以使用request()->ip()
.
Is there a Laravel built-in wayto get the server IP? Or is it something "impossible" (same problem as SERVER_ADDR
reliability)
是否有Laravel 内置方式来获取服务器 IP?或者它是“不可能的”(与SERVER_ADDR
可靠性相同的问题)
回答by Alexey Mezenin
You can use request object:
您可以使用请求对象:
request()->server('SERVER_ADDR');
Or you can use standard PHP way:
或者您可以使用标准的 PHP 方式:
$_SERVER['SERVER_ADDR'];
回答by Imam Assidiqqi
Request::server('SERVER_ADDR')
:)
Request::server('SERVER_ADDR')
:)
URL Reference: https://laravel.com/api/5.3/Illuminate/Http/Request.html
网址参考:https: //laravel.com/api/5.3/Illuminate/Http/Request.html
回答by ujwal dhakal
$_SERVER['SERVER_ADDR']; for server ip
$_SERVER['SERVER_PORT']; for server port