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.
curl_setopt ($http, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt ($http, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($http,CURLOPT_USERAGENT,'XYZ');
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)
But how do I download the same file, I have tried readfile, fopen/fpassthru, file_get_contents but nothing seems to be working.
Readfile gives the error failed to open stream: HTTP request failed! HTTP/1.0 403 Forbidden
Is there a way to provide curl like options with fopen or readfile, I think that may be the easiest approach to solve this. I could not find much help in PHP documentation.
Please help.
You need to attach your special user-agent to the stream context.
From http://www.php.net/manual/en/wrappers.http.php
Example #2 from the link above: