tags:

views:

488

answers:

2

Im using cURL to log into a website and then store a session cookie.

Is there a way I can access that session cookie from another PHP script (in the same dir etc.) Ive tried:

$ch = curl_init();
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_URL, $url);
echo $content = curl_exec ($ch);
curl_close ($ch);

But that doesnt seem to work

+2  A: 

You need to add this as well, to read the file:

curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
Greg
A: 

complete code:

$fp = fopen("cookie.txt", "w");
fclose($fp);
$ch = curl_init();
curl_setopt ($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
curl_setopt($ch, CURLOPT_COOKIEFILE, "cookie.txt");
curl_setopt($ch, CURLOPT_URL, $url);
echo $content = curl_exec ($ch);
curl_close ($ch);

have fun!

safaali