title: Download remote file from webserver in PHP
body: <p>I have access to a playlist file (.m3u) with a link like <code>http://server.ext:port/page.php?username=test&amp;password=pass</code></p>
  
  <p>When I paste this link into my address bar a download of a .m3u file starts and everything seems OK.</p>
  
  <p>I want to filter and organize the contents of this file with my own PHP script.</p>
  
  <p>My works on a local copy of the .m3u file is ok, but I want do this with a remote file instead.</p>
  
  <p>I've tested with <code>file_get_contents</code> and <code>readfile</code> but i get the error message</p>
  
  <blockquote>
    <p>failed to open stream: Connection refused</p>
  </blockquote>
  
  <p>I've tested with curl but I don't really know how to use it.</p>
  
  <pre><code>$url="http://server.ext:port/page.php?username=test&amp;password=pass";
  $agent= 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET
  CLR 1.0.3705; .NET CLR 1.1.4322)';
  
  $ch = curl_init(); 
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  curl_setopt($ch, CURLOPT_USERAGENT, $agent); 
  curl_setopt($ch, CURLOPT_URL,$url); 
  $result=curl_exec($ch);
  var_dump($result);
  </code></pre>
  
  <p>But impossible to connect to server .</p>