cURL / Mailing Lists / curl-and-php / Single Mail

curl-and-php

COOKIEJAR & COOKIEFILE & modifying outgoing cookies

From: Dave <dave_at_cc0.net>
Date: Wed, 16 Mar 2005 20:34:14 -0800

Hello all,

I am working with PHP/Curl:

PHP-5.0.3 and Curl version reports:

$array[version_number] = 461570
$array[age] = 1
$array[features] = 541
$array[ssl_version_number] = 9465935
$array[version] = 7.11.2

I am trying to get a handle on a couple issues...first of which is
understanding the exact flow of JAR/FILE use....

My understanding is that I should use JAR when I have an incoming cookie
that needs to persist over sessions/requests/time and be stored to disk and
I should use FILE when I want to send an outgoing cookie to a server from
that JAR.

JAR=writeonly, FILE=readonly?

Is this a fair assumption?

I then wonder if I should ALWAYS use both JAR and FILE together in order to
store and forward all cookies..or could I use JAR initially during a
login/session and use FILE subsequently to restablish a session (if server
permits).

My next inquiry is how to modify an outgoing cookie...

I receive some cookies and store in a JAR..one of those particular cookies
needs to be a little different than what is handed to me and/or changing
expiration. I have been trying to figure out how to rewrite that particular
cookie on it's way back out toward the server so I don't have to bother
editing the cookie file.

I attempt the following:

$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 4.0)");
curl_setopt($ch, CURLOPT_COOKIEJAR, $cookie_file);
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, http://www.server.com);
curl_exec($ch);

curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 6.0;
Windows NT 4.0)");
curl_setopt($ch, CURLOPT_COOKIEFILE, $cookie_file);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, "http://www.server.com/signin");
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, "user=1234&pass=4567");
curl_setopt($ch, CURLOPT_REFERER, http://www.server.com);
$t = curl_exec($ch);

The JAR file does not exist at this point

curl_close($ch);

The JAR still doesn't exist

$new_ch = curl_init();

The JAR still doesn't exist

$ch = curl_init();

Now it exists.

I figured the easiest way to modify the outgoing cookies is to change the
cookie in the JAR file...but the file doesn't exist until I start another
curl_init with the same var (persistent?).

Anyway...if there is a simple way to modify the outgoing Cookie: and or
modify the headers directly...that would save me a world of troubles...

Any help would be appreciated.

Thanks!

-Dave
Received on 2005-03-17