agent icon indicating copy to clipboard operation
agent copied to clipboard

Cant get User Ip address

Open ErrorDoc404 opened this issue 4 years ago • 4 comments

can you please create a documentation for getting users ip address

ErrorDoc404 avatar Jan 15 '21 08:01 ErrorDoc404

The purpose of this package is to read the UserAgent of the browser, not the request data itself.

What you are looking for is basically $request->ip() or \Request::ip().

darthsoup avatar Jan 16 '21 00:01 darthsoup

$request->ip() or \Request::ip() returns server ip not client ip. how can i get client ip, I am using aws as hosting

ErrorDoc404 avatar Jan 16 '21 11:01 ErrorDoc404

request::ip is the clients IP

However, maybe you have load-balancer / reverse proxy in front and need to check https://www.google.com/search?hl=en&q=http%20x%20forwarder%20for

mfn avatar Jan 18 '21 08:01 mfn

you can use this code to return the client ip

foreach (array('HTTP_CLIENT_IP', 'HTTP_X_FORWARDED_FOR', 'HTTP_X_FORWARDED', 'HTTP_X_CLUSTER_CLIENT_IP', 'HTTP_FORWARDED_FOR', 'HTTP_FORWARDED', 'REMOTE_ADDR') as $key) { if (array_key_exists($key, $_SERVER) === true) { foreach (explode(',', $_SERVER[$key]) as $ip) { $ip = trim($ip); // just to be safe if (filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE) !== false) { return $ip; } } } } return request()->ip(); // it will return server ip when no client ip found

EvilTwin01 avatar Feb 16 '21 08:02 EvilTwin01