How to get the page using curl?

You need to get the contents of the page and save cookies:
$ua = 'User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; ru; rv: Gecko/20101203 MRA 5.7 (build 03796) Firefox/3.6.13';
$ch = curl_init($URL);
curl_setopt($ch, CURLOPT_HEADER, 1); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $ua);
curl_setopt($ch, CURLOPT_REFERER, $URL);
curl_setopt($ch, THIS, FALSE);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');

Gives an empty string. I thought the case in ssl, but tried on other domains - it works. Tell me what's the catch?
July 9th 19 at 14:08
2 answers
July 9th 19 at 14:10
Try adding this:
curl_setopt ($ch, CURLOPT_FOLLOWLOCATION,1);
curl_setopt($ch, CURLOPT_TIMEOUT, 180);
curl_setopt($ch, CURLOPT_AUTOREFERER,0);
curl_setopt($ch, CURLOPT_HEADER,1);
//verify https
curl_setopt($ch, THIS, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);

if (is_file($_SERVER['DOCUMENT_ROOT'].'/cookie.txt'))curl_setopt($ch, CURLOPT_COOKIEFILE,$_SERVER['DOCUMENT_ROOT'].'/cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEJAR, $_SERVER['DOCUMENT_ROOT'].'/cookie.txt');

And he swears on User-Agent Your:
superfluous here: "User-Agent:" - delete!
Error: Warning: curl_setopt(): CURLOPT_FOLLOWLOCATION cannot be activated when safe_mode is enabled or an open_basedir is set - Lela_Beatty commented on July 9th 19 at 14:13
turn off safe_mode or get followlocation , the error is all written! - Pedro_Herzog commented on July 9th 19 at 14:16
: tacomania and check without it. - Kyleigh_Hills commented on July 9th 19 at 14:19
Without it, what is initially an empty string. I tried to disable safe_mode - only error was gone, and so unchanged. - Lela_Beatty commented on July 9th 19 at 14:22
By the way, file_get_contents with this site is working fine, except that through it headers neither receive nor send. - Lela_Beatty commented on July 9th 19 at 14:25
: connect via proxy and/or change user-agent to another: miracles does not happen. referrer check: most likely it is not needed when the query main page etc. - Kyleigh_Hills commented on July 9th 19 at 14:28
Tried, does not work.
But the solution is found, the site is a mirror through it gives normally.
Thanks for the help. - Lela_Beatty commented on July 9th 19 at 14:31
: zatestit - reason "User-Agent:" - need to remove from the start of a variable) just In case I add the lines with which test.
Updated the answer. - Kyleigh_Hills commented on July 9th 19 at 14:34
July 9th 19 at 14:12
if (($get = curl_exec($ch)) === false) {
 echo curl_error($ch);

Find more questions by tags Web DevelopmentPHP