I am trying here to grab the headers and set the headers back so that i can force the download from my php file after http auth done in curl, but no success. curl did not gave any error. nothing returned in $body.
$url=$_GET["url"];//another web server url which forcing file download save as
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_USERPWD, "username:password");//http auth done here
curl_setopt($ch, CURLOPT_HEADER, TRUE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, null);
curl_setopt($ch, CURLOPT_URL, $url);
$response = curl_exec($ch);
list ($headerString, $body) = explode("\r\n\r\n", $response, 2);
$headers = explode("\r\n", $headerString);
foreach ($headers as $header) {
header($header);
}
echo $body;
exit;
code above is working fine. Issue is just & in the $_GET["url"] which splitting valid url. just used urlencode and code working fine now. Hope this will help someone.