I need to POST cookies.txt then download a page to a text file using CURL. This is my FGC example but apparently FGC is bad at cookies so I need CURL.
<?php
$file = file('source\1.txt');
foreach ($file as $link)
{
$link = trim($link);
$link2 = "http://site-that.com/authenticates?={$link}";
$downloaded = file_get_contents($link2);
$myFile = "parsed/$link" . ".txt";
$fh = fopen($myFile, 'a') or die('Cannot open file');
fwrite($fh, $downloaded);
}
$timestamp = time();
rename('source\1.txt', "source/done/done-{$timestamp}.txt");
echo 'Finished';
Any ideas? Code examples would be extremely appreciated. A simple example that does this to like google.com would be great Also, if you have another way to do this that's faster, please post!
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($curl, CURLOPT_COOKIEFILE, $cookieFileName); //$cookieFilename must be a path to a file with cookie data
curl_setopt($curl, CURLOPT_COOKIEJAR, $cookieFileName);
//curl_setopt($curl, CURLOPT_COOKIE, $cookie); //you may also use this, here $cookie is a cookie string
curl_close($curl);
$data = curl_exec($curl);
来源:https://stackoverflow.com/questions/16656611/download-a-file-via-curl-with-cookies-using-php