Page 1 of 1

curl postfields issue

Posted: Wed Nov 04, 2009 3:35 pm
by lmchaelichkatel
Hi

I have an array which I send with CURLOPT_POSTFIELDS option in curl_setopt.
Image

Code: Select all

 
$tab = array();
$tab['search'] = '';
$tab['filter_sectionid'] = '16'; 
$tab['catid'] = '0';
$tab['filter_authorid'] = '0';
$tab['filter_state'] = 'U';
$tab['toggle'] = '';
$tab['limit'] = '0';
$tab['limitstart'] = '0';
$tab['option'] = 'com_content';
$tab['task'] = 'remove';
$tab['boxchecked'] = '2';   
$tab['redirect'] = '-1';
$tab['filter_order'] = 'section_name';
$tab['filter_order_Dir'] = '';
 
Well I need to add to this array $tab the values of cid[] but in php an array can countain only a unique key, so I can't do this :

Code: Select all

 
$tab = array();
$tab['search'] = '';
$tab['filter_sectionid'] = '16'; 
$tab['catid'] = '0';
$tab['filter_authorid'] = '0';
$tab['filter_state'] = 'U';
$tab['toggle'] = '';
$tab['limit'] = '0';
$tab['limitstart'] = '0';
$tab['option'] = 'com_content';
$tab['task'] = 'remove';
$tab['boxchecked'] = '2';   
$tab['redirect'] = '-1';
$tab['filter_order'] = 'section_name';
$tab['filter_order_Dir'] = '';
// Add cid[] values
$tab['cid[]'] = '48';
$tab['cid[]'] = '47';
$tab['cid[]'] = '46';
$tab['cid[]'] = '42'; 
 
In this case I am blocked I don't know how to construct this array or send data using string instead of an array ?

Code: Select all

 
task=remove&boxchecked=2&redirect=-1filter_order=section_namefilter_order_Dir=&cid[]=48&cid[]=47&cid[]=46&cid[]=42
 
Think you

Re: curl postfields issue

Posted: Wed Nov 04, 2009 4:05 pm
by requinix
For the CID use

Code: Select all

$tab["cid"] = array();
$tab["cid"][] = 48;
$tab["cid"][] = 47;
$tab["cid"][] = 46;
$tab["cid"][] = 42;

Re: curl postfields issue

Posted: Wed Nov 04, 2009 4:36 pm
by McInfo
Duplicate post: 108474

Code: Select all

$fields = array
(   'a' => '1'
,   'b' => array('1', '2', '3')
,   'c' => array
    (   'ca' => '1'
    ,   'cb' => '2'
    ,   'cc' => '3'
    )
);
print_r($fields);
 
$postfields = http_build_query($fields, '_', '&');
echo urldecode($postfields);
// a=1&b[0]=1&b[1]=2&b[2]=3&c[ca]=1&c[cb]=2&c[cc]=3
 
//curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
PHP Manual: http_build_query()

Edit: This post was recovered from search engine cache.

Re: curl postfields issue

Posted: Wed Nov 04, 2009 5:06 pm
by lmchaelichkatel
Thinks for your replies. Is it mandatory to pass string by urlencode before send it to CURLOPT_POSTFIELDS ? because I don't use urlencode when I send array and I don't use it in CURLOPT_URL too, I send the url with & directly and it works.

Think you

Re: curl postfields issue

Posted: Wed Nov 04, 2009 6:42 pm
by McInfo
I used urlencode() to make the echoed string easier to read. The string stored in $postfields was not changed.
lmchaelichkatel wrote:Think
Thank

Edit: This post was recovered from search engine cache.