First of all you have to figure out a way to determine the "client".
Is it a logged in user or just a visitor?
Usually you should just be able to look in the $_SERVER variable..
Without knowing details about your hosting setup it's hard to give you a proper answer. It sounds like you might be behind a proxy or some kind of load balancer? You can try doing:
in a test route/view, and see what all the variables are coming back as. Figure out which one has your IP when you're looking at this on your host and that's the variable you need to use.
Request::getClientIp() should work, but you might need to setup trusted proxies, if you are behind some kind of proxy and the IP is passed as x-forwarded-for header. See http://symfony.com/doc/current/components/http_foundation/trus...
Did you try some
Request::getClientIp(true) public string getClientIp(Boolean $proxy = false)
Returns the client IP address. This method can read the client IP address from the "X-Forwarded-For" header when trusted proxies were set via "setTrustedProxies()". The "X-Forwarded-For" header value is a comma+space separated list of IP addresses, the left-most being the original client, and each successive proxy that passed the request adding the IP address where it received the request from. If your reverse proxy uses a different header name than "X-Forwarded-For", ("Client-Ip" for instance), configure it via "setTrustedHeaderName()" with the "client-ip" key.
The proxy parameter was deprecated and is removed, it doesn't exist in 2.5 anymore.
I personally use this code block,
$request = Request::instance(); $request->setTrustedProxies(array('127.0.0.1')); // only trust proxy headers coming from the IP addresses on the array (change this to suit your needs) $ip = $request->getClientIp();
Hope this will help.
Sign in to participate in this thread!
We'd like to thank these amazing companies for supporting us
The Laravel portal for problem solving, knowledge sharing and community building.