sarfraznawaz2005/visitlog

the app is host on a remote web server but the IP log still 127.0.0.1

Closed this issue · 3 comments

Thanks for this great package but i have a problem, the app is host on a remote server but the IP log still 127.0.0.1 for all request and only IP, browser, OS lof value others fields are empty. any idea?

Can you tell what output do you get when you run this in app:

request()->ip()

And what output you get when you run this code in your app:

protected function getUserIP()
{
	$client = @$_SERVER['HTTP_CLIENT_IP'];
	$forward = @$_SERVER['HTTP_X_FORWARDED_FOR'];
	$remote = @$_SERVER['REMOTE_ADDR'];
	
	if (filter_var($client, FILTER_VALIDATE_IP)) {
		$ip = $client;
	} elseif (filter_var($forward, FILTER_VALIDATE_IP)) {
		$ip = $forward;
	} else {
		$ip = $remote;
	}
	
	return $ip ?: '0.0.0.0';
}

If you still get 127.0.0.1 in both cases then there is something up with your server config.

Thanks for your quick response,
request()->ip() return as well 127.0.0.1
But this code $client = isset($_SERVER['HTTP_CLIENT_IP']) ? $_SERVER['HTTP_CLIENT_IP'] : isset($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR'];
dd($client) return this: 190.115.179.219, 127.0.0.1

I solved it by adding $_SERVER['REMOTE_ADDR'] = $_SERVER['HTTP_X_REAL_IP'];
Thanks for your suport !