CURL and COOKIES

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
alexeiz
Forum Newbie
Posts: 12
Joined: Mon Oct 20, 2003 9:31 pm
Location: Los Angeles

CURL and COOKIES

Post by alexeiz »

I've tried using CURL functions to simulate login form and everything work except setting cookies!

I stripped the code down to its simplest form (where $post_arr is an array holding username, password and action evoked by submit button):

if (!$curl2 = curl_init()) return "Bad connection!";
curl_setopt($curl2, CURLOPT_POST, true);
curl_setopt ($curl2, CURLOPT_HEADER,1);
curl_setopt($curl2, CURLOPT_POSTFIELDS,$post_arr);
curl_setopt($curl2, CURLOPT_URL, $url;
curl_setopt($curl2, CURLOPT_COOKIE, "user=username");
$output2 = curl_exec($curl2);
curl_close($curl2);
echo $output2;

This script does everything right, except the cookie doesn't get set, period!
I also tried CURLOPT_COOKIEJAR in the previous script (it writes to the file "cookies.txt" correctly) and then including CURLOPT_COOKIEFILE , "cookies.txt" in the next script - just doesn't work - no cookies are set.
I'm really stuck - PLEASE HELP!
Post Reply