Issue
I am working on a script for downloading and scanning particular webpage elements I am trying to download this example page with PHP cURL:
rel="nofollow">http://www.jetbull.com/Deposit
However, every time I attempt the curl_exec() the output file is empty. Would anyone know why this is or be able to lead me on the path to fixing this?
I am easily able to use pretty much any other URL in this function and this won't happen.
function download_page($url, $out_file = "body.txt") {
$fp = fopen($out_file, "w");
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_exec($ch);
fclose($fp);
$details = curl_getinfo($ch);
curl_close($ch);
return $details;
}
$url = "http://www.jetbull.com/Deposit";
download_page($url);
I am running PHP 5.2.6 inside a nix environment. I can see clearly the page will return a 307, though I am unsure as to why a redirect isn't followed (if that is indeed the problem).
In Firefox, this page is retrieved fine, with a reported HTTP 200. Is the server responding in some non-standard fashion that cURL isn't handling, or is cURL not following the redirect properly, else am I doing something else just plain silly?
Any help at all for information on how to fix this or to lead me down the path would be very appreciated!
Solution
Add this option
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
Answered By - kolomiets Answer Checked By - Willingham (WPSolving Volunteer)