I'm just trying to obtain some cookies from a website using curl, I've read thousands of topics related with this, the problem was in almost every case related to the path to the file (which must be absolute).
I tried several things but I can not find the reason why my cookies are not being written. Here I go with the code:
$cookieDir = 'tmp/cookies.txt';
$options = Array(
CURLOPT_RETURNTRANSFER => TRUE,
CURLOPT_URL => $url,
CURLOPT_COOKIEJAR => realpath($cookieDir),
CURLOPT_COOKIEFILE => realpath($cookieDir)
);
$ch = curl_init();
curl_setopt_array($ch, $options);
ob_start();
$data = curl_exec($ch);
ob_end_clean();
curl_close($ch);
Some annotations:
- The file exists
- realpath($cookieDir) is writable
- I'm getting the website in $data without troubles
Thank you guys