cURL and COOKIES -How to set?

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 -How to set?

Post by alexeiz »

I'm trying to set cookies when posting to a page.

I got the script practically copied from PHP Cookbook with minor alterations:

$post_arr = array (username =>'alexeiz' ,password =>'GOVNO32');
$c = curl_init('http://www.alexeiz.com/hit.php');
curl_setopt($c,CURLOPT_VERBOSE,1);
curl_setopt($c,CURLOPT_COOKIE,'user=MUDAK');
curl_setopt($c, CURLOPT_POSTFIELDS, $post_arr);
curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
$page = curl_exec($c);
curl_close($c);

echo "<br> $page";
Postfields are posted OK, but the cookie is never set - tried many times in different enviroments.

What could be the problem? PHP is 4.3.2, cURL 7.10.3
User avatar
Stoker
Forum Regular
Posts: 782
Joined: Thu Jan 23, 2003 9:45 pm
Location: SWNY
Contact:

Post by Stoker »

Perhaps you are missunderstanding the http protocol a bit, you can not "set" a cookie at a webserver, curl is a client so your script is the one holding a cookie, when you set the curl cookie options it is to give that cookie value to the webserver...
alexei
Forum Newbie
Posts: 9
Joined: Wed Jul 09, 2003 5:44 pm
Location: Los Angeles, CA, USA

I do misunderstand!

Post by alexei »

Thanks, I do misunderstand I guess!

Let me explain what my end goal is - I'm posting to a login page that requires username and password.

When I login to this page manually, I also set cookies holding username and password so I could access other protected pages.

I was told by about 5-6 different sources that what I have to do to simulate manual login is to extract the info on these cookies from the header returned and then submit them back in the next cURL submission to the same page using either CURLOPT_COOKIE or CURLOPT_COOKIEJAR and CURLOPT_COOKIEFILE

I tried all possible combinations using numerous examples and never succeeded. The example I posted is stripped down and tries to set a different cookie on purpose.

I would appreciate any suggestion that would lead to successful login AND setting of username and password cookies from the script.
Post Reply