Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is Laravel 5 removing REMOTE_ADDR from Server object?

Tags:

php

laravel-5

I hope someone has seen this before, I've been searching Google and getting nowhere.

I'm trying to do something very simple, retrieve REMOTE_ADDR from $_SERVER object but it simply equates to true (1).

I am convinced this is a config issue related to laravel but have no idea where to start digging.

The contents of $_SERVER are as follows (obviously I've removed potentially sensitive paths etc.)

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'

Note the REMOTE_ADDR = '1'

What is going on there?

I have tried simply creating a test.php file in a /var/www/myapp/public/ as follows

<?php
print_r($_SERVER)

and it gives me the REMOTE_ADDR correctly, which is what leads me to believe it is a laravel issue.

If anyone can suggest why this is happening and what I can do about it, it would be greatly appreciated.

Relevant version numbers:

OS: Debian 7

nginx: 1.2.1

php: 5.4.39

Laravel 5

like image 434
Darren H Avatar asked Jun 26 '15 15:06

Darren H


2 Answers

Try using Request::ip(); and your problem is solved. I know this is not a very constructive answer but it solves your problem.

like image 174
Khan Shahrukh Avatar answered Nov 19 '22 02:11

Khan Shahrukh


In laravel 5

public function index(Request $request) {

    $request->ip();
}
like image 35
Govind Samrow Avatar answered Nov 19 '22 04:11

Govind Samrow