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


Bug or strange behavior with CURLOPT_COOKIE: cookie value disappears

From: Mikkel T. Kromann <>
Date: Mon, 24 Mar 2008 13:49:54 +0100


I have a strange problem (possibly a bug, or possibly my lack of
understanding of curl or cookies or both).

When I try to use CURLOPT_COOKIE I'm not able to set the value of the
cookie to anything but empty (print_r($_COOKIE) shows only the cookie
name as key, while the value is empty).

This problem is only with my local SuSE linux 10.2 installation, but not
on my web hotel. Perhaps some of you could kindly point me to some
configuration option that I've missed, or to an appropriate updated
version of php/curl?

I've created two small scripts (supplied below) for reproduction of the
behavior (link to output supplied below). A target script which returns
the content of the $_COOKIE variable and a wrapper script which supplies
the target script with a cookie prints the output of the target script.

I'd be happy to supply further information (version information supplied
below) - just tell me what you need (and perhaps how - I'm not that
fluid in http headers ;) ...

Another question: Could anyone perhaps supply an example of using
CURLOPT_COOKIE with multiple cookies which contain expiration dates and
paths? (btw: that would be nice to have in the PHP documentation ...)



>uname -a
Linux scrat #1 SMP Tue Apr 17 08:42:35 UTC 2007
i686 i686 i386 GNU/Linux

> curl _V
curl 7.15.5 (i686-suse-linux-gnu) libcurl/7.15.5 OpenSSL/0.9.8d
zlib/1.2.3 libidn/0.6.8
Protocols: tftp ftp telnet dict ldap http file https ftps
Features: IDN IPv6 Largefile NTLM SSL libz

# This is the contents of target.php
<?php print_r($_COOKIE); ?>

# This is the contents of wrapper.php
print "This is the $_COOKIE array output by target.php \r\n";
$ch = curl_init("");
curl_setopt($ch, CURLOPT_COOKIE, "id=242; ");
$test = curl_exec($ch);
print $test;

I've saved the output of wrapper.php on a public website for your
inspection (details of the problem php installation supplied there):

Received on 2008-03-24