title: file_get_contents($url): failed to open stream error while trying to access a url directly
body: <p>In my laravel app I installed <code>stevebauman/location": "1.3.*</code></p>
  
  <p>It works just fine in my local server. After I uploaded it to the remote server, this line</p>
  
  <p><code>$contents = json_decode(file_get_contents($this-&gt;url.$ip), true);</code> </p>
  
  <p>in the file </p>
  
  <p><code>F:\xampp\htdocs\news5.2.23\vendor\stevebauman\location\src\Drivers\FreeGeoIp.php</code></p>
  
  <p>is throwing the error I mentioned.</p>
  
  <p>I searched a lot and tried the following:</p>
  
  <ul>
  <li>I echoed the $url and then copied and directly put in browser, it's all right.</li>
  <li><code>allow_ini_set("allow_url_include", "on");ini_set("allow_url_fopen", "on");</code> wrote it in index.php</li>
  <li><p>used curl .I will provide the FreeGeoIp Class whereI used curl for testing</p>
  
  <pre><code>&lt;?php
      namespace Stevebauman\Location\Drivers;
  
      use Stevebauman\Location\Objects\Location;
      use Stevebauman\Location\Location as LocationInstance;
  
      class FreeGeoIp implements DriverInterface
      {
          /**
           * Holds the current Location class instance.
           *
           * @var LocationInstance
          */
          private $instance;
  
          /**
           * Holds the configuration instance.
           *
           * @var \Illuminate\Config\Repository
          */
          private $config;
  
          /*
           * Holds the drivers URL
           */
          private $url;
  
          /**
           * Constructor.
           *
           * @param LocationInstance $instance
          */
          public function __construct(LocationInstance $instance)
          {
              $this-&gt;instance = $instance;
  
              $this-&gt;config = $this-&gt;instance-&gt;getConfig();
  
              $this-&gt;url = $this-&gt;config-&gt;get('location.drivers.FreeGeoIp.url');
          }
  
          /**
           * Retrieves the location from the driver FreeGeoIp and returns a    location object.
           *
           * @param string $ip
           *
           * @return Location
          */
           public function get($ip){
  
               $location = new Location();
               $file = $this-&gt;file_get_contents_curl(urlencode($this-&gt;url.$ip));
               die();       
  
              return $location;
          }
  
          public function file_get_contents_curl($url) {
  
              $ch = curl_init($url);
              curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
              curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
              curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
              curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
              var_dump($ch);
              $data = curl_exec($ch);
              if($errno = curl_errno($ch)) {
                  $error_message = curl_strerror($errno);
                  echo "cURL error ({$errno}):\n {$error_message}.&lt;/br&gt;";
              }
              curl_close($ch);
              return $data;
          }
      } 
  </code></pre></li>
  </ul>
  
  <p>Then I found this error</p>
  
  <blockquote>
    <p>cURL error (6): Couldn't resolve host name.</p>
  </blockquote>
  
  <p>Finally I got somewhere that maybe the server <em>my site is in has a firewall which is blocking outsourced url call</em>.  <strong>I dont know why that would be!</strong></p>
  
  <p>Interestingly when I tried <code>return redirect('http://freegeoip.lwan.ws/json/visitor_ip')</code> - this line in a function of one of my Controllers, it worked! </p>
  
  <p>So I have to discard the firewall issue also right?</p>
  
  <p>But when I use <code>file_get_contents('http://freegeoip.lwan.ws/json/visitor_ip')</code> in the same function, it doesn't work again.</p>
  
  <p><strong>People seem to be answering my question without reading it at all. Giving me answers which I already tried and mentioned.Please read.</strong></p>