Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cant get User Ip address #181

Open
ErrorDoc404 opened this issue Jan 15, 2021 · 4 comments
Open

Cant get User Ip address #181

ErrorDoc404 opened this issue Jan 15, 2021 · 4 comments

Comments

@ErrorDoc404
Copy link

can you please create a documentation for getting users ip address

@darthsoup
Copy link

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().

@ErrorDoc404
Copy link
Author

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

@mfn
Copy link

mfn commented Jan 18, 2021

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

@EvilTwin01
Copy link

EvilTwin01 commented Feb 16, 2021

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants
@mfn @darthsoup @EvilTwin01 @ErrorDoc404 and others