Why php curl does not save cookie in my cookiefile?
When setting CURLOPT_COOKIEJAR
, you need to use an absolute path. You can do this easily by using:
curl_setopt ($ch, CURLOPT_COOKIEJAR, realpath($cookie_file) );
Reference: cannot use cookies in cURL PHP
Yes realpath works, but remember that (thanks to php.net) before second call of curl_exec, CURLOPT_COOKIEFILE should be the same as in previous setting of CURLOPT_COOKIEJAR - because it is used for reading from "jared" file :)
//my working snippet for one php file://....curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('test2-cookie.txt'));$content = curl_exec($ch);curl_close($ch); $ch = curl_init(); curl_setopt($ch, CURLOPT_COOKIEJAR, realpath('test2-cookie.txt'));curl_setopt ($ch, CURLOPT_COOKIEFILE, realpath('test2-cookie.txt'));$content = curl_exec($ch);//second call