$url = 'https://ntschool.ru/kursyi'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64;rv:38.0) Gecko/20100101 Firefox/38.0"); curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER , true); $content = curl_exec($ch); curl_close($ch); var_dump($content); 

var_dump shows false, when you try to write it to the file file_put_contents ('1', $ content) creates an empty file, I don’t understand why it doesn’t work, curl does not issue any errors

  • error output is enabled? looked in the logs? - Vorobev Alexander
  • You can get a description of the error as follows: $error = curl_error($ch); . There is a suspicion that ssl verification does not work, try setting the CURLOPT_SSL_VERIFYHOST and CURLOPT_SSL_VERIFYPEER to false ; - Yegor Banin
  • one
    Possible duplicate question: Curl and Https? - Visman

2 answers 2

Because Google uses HTTPS, add this:

 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); 
  • Thank you so much! it worked - Anton Kucenko
  • Can you explain what these options do? from the documentation is not particularly clear - Anton Kucenko
  • one
    @AntonKucenko disable the authentication of the server certificate and the name of the host to which the certificate is issued. - Hombre
  • @Hombre remains incomprehensible: why doesn't it work without shutting down? - andreymal

Actually, the code works. Everything is recorded as it should. Protestit. Look for a problem not in the code.

 <?php $url = 'https://ntschool.ru/kursyi'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 6.1; WOW64;rv:38.0) Gecko/20100101 Firefox/38.0"); curl_setopt($ch, CURLOPT_REFERER, 'https://www.google.com'); curl_setopt($ch, CURLOPT_RETURNTRANSFER , true); $content = curl_exec($ch); curl_close($ch); file_put_contents('site.html', $content); ?> 
  • You most likely visited this site in a browser, and only then ran the code, didn't you? ;) - Daniel Protopopov
  • No, it's just the whole thing in direct hands;) My code worked without turning off certificate checking in CURL, so I didn’t mention this setting. - Denis