为什么Laravel 5从Server对象中删除REMOTE_ADDR?

时间:2015-06-26 15:56:20

标签: php laravel-5

我希望有人之前见过这个,我一直在搜索谷歌而无处可去。

我正在尝试做一些非常简单的事情,从$ _SERVER对象中检索REMOTE_ADDR,但它只是等于true(1)。

我确信这是与laravel相关的配置问题,但不知道从哪里开始挖掘。

$ _SERVER的内容如下(显然我已经删除了可能敏感的路径等。)

var list = data.Where(x => x.StationName.ToUpper().Contains(search.ToUpper()));

注意REMOTE_ADDR ='1'

那里发生了什么?

我试过在/ var / www / myapp / public /中创建一个test.php文件,如下所示

USER = '[REMOVED]'
HOME = '[REMOVED]'
FCGI_ROLE = 'RESPONDER'
REDIRECT_HANDLER = 'php5-fcgi'
REDIRECT_STATUS = '200'
HTTP_HOST = '[REMOVED]'
HTTP_CONNECTION = 'keep-alive'
HTTP_ACCEPT = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8'
HTTP_USER_AGENT = 'Mozilla/5.0 (Linux; Android 5.0.1; GT-I9505 Build/LRX22C) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.93 Mobile Safari/537.36'
HTTP_REFERER = '[REMOVED]'
HTTP_ACCEPT_ENCODING = 'gzip, deflate, sdch'
HTTP_ACCEPT_LANGUAGE = 'en-GB,en-US;q=0.8,en;q=0.6'
PATH = '/usr/local/bin:/usr/bin:/bin'
SERVER_SIGNATURE = 'Apache/2.2.22 (Ubuntu) Server at [REMOVED] Port 80'
SERVER_SOFTWARE = 'Apache/2.2.22 (Ubuntu)'
SERVER_NAME = '[REMOVED]'
SERVER_ADDR = '[REMOVED]'
SERVER_PORT = '80'
REMOTE_ADDR = '1'
DOCUMENT_ROOT = '[REMOVED]'
SERVER_ADMIN = '[REMOVED]'
SCRIPT_FILENAME = '[REMOVED]'
REMOTE_PORT = '48650'
REDIRECT_QUERY_STRING = '[REMOVED]'
REDIRECT_URL = '/index.php'
GATEWAY_INTERFACE = 'CGI/1.1'
SERVER_PROTOCOL = 'HTTP/1.1'
REQUEST_METHOD = 'GET'
QUERY_STRING = '[REMOVED]'
REQUEST_URI = '[REMOVED]'
SCRIPT_NAME = '/index.php'
ORIG_SCRIPT_FILENAME = '[REMOVED]'
ORIG_PATH_INFO = '/index.php'
ORIG_PATH_TRANSLATED = '[REMOVED]'
ORIG_SCRIPT_NAME = '/php5-fcgi'
PHP_SELF = '/index.php'
REQUEST_TIME = '1435331181'

它正确地给了我REMOTE_ADDR,这让我相信它是一个laravel问题。

如果有人能够说明为什么会这样,以及我能做些什么,我们将不胜感激。

相关版本号:

  

操作系统:Debian 7

     

nginx:1.2.1

     

php:5.4.39

     

Laravel 5

2 个答案:

答案 0 :(得分:5)

尝试使用Request :: ip();你的问题解决了。我知道这不是一个非常有建设性的答案,但它解决了你的问题。

答案 1 :(得分:2)

在laravel 5中

public function index(Request $request) {

    $request->ip();
}