Why such a code does not save cookies?

$ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'https://ocservice.taobao.com/cookieController/processUserCookie?site=CN_zh-CN_CNY_156&callback=jsonp_1546706091271_92560'); curl_setopt($ch, CURLOPT_NOBODY, true); curl_setopt($ch, CURLOPT_COOKIEJAR, dirname(__FILE__) . '/cookie.txt'); $http_headers = array( 'Host: www.google.ca', 'User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2', 'Accept: */*', 'Accept-Language: en-us,en;q=0.5', 'Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7', 'Connection: keep-alive' ); curl_setopt($ch, CURLOPT_HEADER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $http_headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_TIMEOUT, 10); $output = curl_exec($ch); curl_close($ch); 

    2 answers 2

    I forgot to process https, so this script does not work in principle from the word in general:

     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 

    See the documentation carefully.

       curl_setopt($ch, CURLOPT_COOKIEJAR, __DIR__ . "/cookies.txt"); curl_setopt($ch, CURLOPT_COOKIEFILE, __DIR__ . "/cookies.txt");