title: How to download a file over https using php
body: <p>I need to download an xml file using PHP. I am able to read the contents of file by setting following options when making a curl call to it.</p>
  
  <pre><code>curl_setopt ($http, CURLOPT_SSL_VERIFYPEER, false);
  curl_setopt ($http, CURLOPT_SSL_VERIFYHOST, false);
  curl_setopt($http,CURLOPT_USERAGENT,'XYZ');
  </code></pre>
  
  <p>As evident from above snippet I need to make VERIFYHOST as false and also need to set an explicit USERAGENT when making a call to read the file because the file is not publicly accessible and only a specific application can make call to read it (Web-Security techniques and stuff)</p>
  
  <p>But how do I download the same file, I have tried <code>readfile</code>, <code>fopen/fpassthru</code>, <code>file_get_contents</code> but nothing seems to be working.
  Readfile gives the error <code>failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden</code></p>
  
  <p>Is there a way to provide curl like options with <code>fopen</code> or <code>readfile</code>, I think that may be the easiest approach to solve this. I could not find much help in PHP documentation.</p>
  
  <p>Please help.</p>