php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #62942 Setting CURLOPT_COOKIE with curl_setopt_array problem
Submitted: 2012-08-27 01:53 UTC Modified: 2017-01-28 12:16 UTC
Votes:3
Avg. Score:3.3 ± 0.5
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:1 (33.3%)
From: ben at blinkmobile dot com dot au Assigned:
Status: Open Package: cURL related
PHP Version: 5.3.16 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: ben at blinkmobile dot com dot au
New email:
PHP Version: OS:

 

 [2012-08-27 01:53 UTC] ben at blinkmobile dot com dot au
Description:
------------
Setting CURLOPT_COOKIE with curl_setopt_array must be done before setting 
CURLOPT_COOKIEFILE or CURLOPT_COOKIEJAR.

I'm not sure if this is a bug, however I can't find documentation explaining that 
when using curl_setopt_array you need to set options in a particular order.

It was working in PHP 5.3.13, however fails in 5.3.14 + 5.3.15

A change that could have caused this is https://bugs.php.net/bug.php?id=61948

Test script:
---------------
$cookies = 'a=b';

// the following correctly attaches $cookies in PHP 5.3.13 but not PHP 5.3.14+
$options = array(

	CURLOPT_URL => 'http://...',
	CURLOPT_COOKIEFILE => '',
	CURLOPT_COOKIEJAR => '',
        CURLOPT_HEADER => true,
        CURLOPT_COOKIE => $cookies,
);


$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);


// the following attaches $cookies correctly for all versions I have tested
$options = array(

	CURLOPT_URL => 'http://...',
        CURLOPT_COOKIE => $cookies,
	CURLOPT_COOKIEFILE => '',
	CURLOPT_COOKIEJAR => '',
        CURLOPT_HEADER => true,
);


$ch = curl_init();
curl_setopt_array($ch, $options);
curl_exec($ch);
curl_close($ch);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-08-27 02:55 UTC] laruence@php.net
it's not a bug, cookie_*** options are exclusive
 [2012-08-27 03:59 UTC] ben at blinkmobile dot com dot au
Thanks Laruence. Is this documented anywhere? I couldn't find it.

Also, it appears that curl_setopt isn't enforcing the exclusivity. The following 
2 tests both attach $cookies fine on PHP 5.3.15:

$cookies = 'a=b';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://...');
curl_setopt($ch, CURLOPT_COOKIE, $cookies);
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
curl_setopt($ch, CURLOPT_COOKIEJAR, '');
curl_setopt($ch, CURLOPT_HEADER, true);

curl_exec($ch);
curl_close($ch);


$cookies = 'a=b';

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://...');
curl_setopt($ch, CURLOPT_COOKIEFILE, '');
curl_setopt($ch, CURLOPT_COOKIEJAR, '');
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_COOKIE, $cookies);

curl_exec($ch);
curl_close($ch);


I notice that the curl library between my tests was upgraded from 7.19.7 to 
7.24.0. Perhaps it was this and not https://bugs.php.net/bug.php?id=61948 ?

If there is documentation for this exclusivity it would be good to include a link 
here and on http://au2.php.net/manual/en/function.curl-setopt.php and 
http://au2.php.net/manual/en/function.curl-setopt-array.php because people's 
existing (however incorrect) code might break when they upgrade PHP or CURL.
 [2012-11-15 05:55 UTC] pierrick@php.net
-Package: cURL related +Package: Documentation problem
 [2012-11-15 05:55 UTC] pierrick@php.net
As mentioned by Laruence, this is not a bug, cookie_*** options are exclusive and 
libcurl don't report this kind of error so that we can report it on the user 
space.

To be documented
 [2016-06-21 18:22 UTC] cmb@php.net
Hm, I can't reproduce any of this behavior with PHP 5.2.17 (cURL
7.21.0) or PHP 5.6.15 (cURL 7.41.2) on Windows. Using both
CURLOPT_COOKIE and CURLOPT_COOKIEFILE works fine (neither the
order does matter nor whether they're set via curl_setopt() or
curl_setopt_array()).
 [2017-01-28 12:16 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: Documentation problem +Package: cURL related
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 14:01:29 2024 UTC