I need to get my users IP address'.
I found this article How to get Client Ip Address in Laravel 5.1?
The above mentioned article uses the Request::ip();
However, this method returns my servers IP address. From what I can understand from other sources, this happens when the site is localhost - but the site is hosted and is live on a server.
This site is live and online, but it might refer to localhost
, as the site might be sitting on its own server (I dont have any experience in server config to know if this is true or not, just a guess).
When I connect to the DB Host, I do so using localhost
referencing as well, and not something like mysql.phpmyadmin.hosting.com
as DB Host. Therefore, my guess is, that the Request::ip();
returns the server ip, because the site somehow is sitting localhost.
However, if I use $_SERVER['HTTP_X_FORWARDED_FOR']; I get the correct IP address.
Now to my final question: Is this safe to use? Is there another way to use a Laravel function to make this request?
From what I can understand, the $_SERVER['HTTP_X_FORWARDED_FOR']; can have security holes, according to How to get the client IP address in PHP?.
Can I use $_SERVER['HTTP_X_FORWARDED_FOR'];
safely without worrying? If not, what other way could I go, to get the users IP address safely?