title: Get User IP address in laravel with similar method to HTTP_X_FORWARDED_FOR
body: <p>I need to get my users IP address'. </p>
  
  <p>I found this article <a href="https://stackoverflow.com/questions/33268683/how-to-get-client-ip-address-in-laravel-5-1">How to get Client Ip Address in Laravel 5.1?</a> </p>
  
  <p>The above mentioned article uses the <code>Request::ip();</code></p>
  
  <p>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.</p>
  
  <p>This site is live and online, but it might refer to <code>localhost</code>, 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).</p>
  
  <p>When I connect to the DB Host, I do so using <code>localhost</code> referencing as well, and not something like <code>mysql.phpmyadmin.hosting.com</code> as DB Host. Therefore, my guess is, that the <code>Request::ip();</code> returns the server ip, because the site somehow is sitting localhost.</p>
  
  <p>However, if I use $_SERVER['HTTP_X_FORWARDED_FOR']; I get the correct IP address. </p>
  
  <p>Now to my final question: <strong>Is this safe to use?</strong> Is there another way to use a Laravel function to make this request?</p>
  
  <p>From what I can understand, the $_SERVER['HTTP_X_FORWARDED_FOR']; can have security holes, according to <a href="https://stackoverflow.com/questions/3003145/how-to-get-the-client-ip-address-in-php">How to get the client IP address in PHP?</a>. </p>
  
  <p><strong>Can I use <code>$_SERVER['HTTP_X_FORWARDED_FOR'];</code> safely without worrying? If not, what other way could I go, to get the users IP address safely?</strong></p>