About Curl

Hello,

[php]$arr = array(“aaa” => 1, “bbb” => “test”, “ccc” => 0, “ddd” => 0, “eee” => 0, “fff” => 1);[/php]
[php] $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($arr));
curl_setopt($ch, CURLOPT_POSTFIELDS, $arr);
curl_setopt($ch, CURLOPT_TIMEOUT,300);
$out = curl_exec($ch);
$output = trim($out);
curl_close($ch);[/php]

[php]echo $output[/php]
Output:
Array( [aaa] => 1 [bbb] => test [ccc] => 0 [ddd] => 0 [eee] => 0 [fff] => 1)Action successful
Ok message this: Action successful
Why array are returned? Where am I doing wrong?

Thanks

What are you expecting to be returned? Just because you are using cURL does not mean you will get a specific format back.

It’s not the array I sent, Only URL page results

SO???

And what is on the end of the url?

You can do a cURL request to anything.

[php]
function cURL($url){
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_TIMEOUT,300);
curl_setopt ( $ch, CURLOPT_FOLLOWLOCATION, TRUE);
$out = curl_exec($ch);
$output = trim($out);
curl_close($ch);
return $output;
}

echo cURL(‘phphelp.com’);
[/php]

Sorry.

URL file forgotten this code
print_r($_POST);

Again sorry

If your output is the array, how is that not what you sent?

Hello,

[php]$arr = array(“aaa” => 1, “bbb” => “test”, “ccc” => 0, “ddd” => 0, “eee” => 0, “fff” => 1);[/php]
The above array is sending smoothly. No problem

I need to add a second array
[php]Array ( [tablolar] => Array ( [0] => gggg [1] => hhhh [2] => iiii [3] => jjjj [4] => kkkk [5] => llll [6] => mmmm);[/php]

Does not send second array $arr2

[php]$arrays = array_merge($arr, arr2);[/php]
[php] $ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, false);
curl_setopt($ch, CURLOPT_POST, count($arrays));
curl_setopt($ch, CURLOPT_POSTFIELDS, $arrays);
curl_setopt($ch, CURLOPT_TIMEOUT,300);
$out = curl_exec($ch);
$output = trim($out);
curl_close($ch);[/php]

Merged topics. You already have the exact topic opened.

The second array will not work, because it is multidimensional. It is actually better to convert the arrays to a json string and sent it over that way.

I solved the problem as follows
[php] foreach($tabdiz AS $key => $value) {
$tabdiz_string .= ‘tablolar[]=’.$value.’&’;
}
rtrim($tabdiz_string, ‘&’);
Print:
tablolar[]=gggg&tablolar[]=hhhh&tablolar[]=iiii&tablolar[]=jjjj&tablolar[]=kkkk&tablolar[]=llll&

        foreach($tablodizi AS $key => $value) { 
            $tablodizi_string .= $key.'='.$value.'&'; 
            }
        rtrim($tablodizi_string, '&');
        print:
        aaa=1&bbb=test&ccc=0&ddd=0&eee=0&fff=2&
       
       $allarrays = $tabdiz_string.$tablodizi_string;[/php]

Which is right ?

My code OR json string ?

Your code definitely isn’t right.

What is this:
[php]Print:
tablolar[]=gggg&tablolar[]=hhhh&tablolar[]=iiii&tablolar[]=jjjj&tablolar[]=kkkk&tablolar[]=llll&[/php]

That print looks dangerously like a goto label.

json_encode turns arrays into strings. It is a lot easier than nested loops doing who knows what.

I have two arrays
No problem in this array.: $arr = array(“aaa” => 1, “bbb” => “test”, “ccc” => 0, “ddd” => 0, “eee” => 0, “fff” => 1); That is all, OK

Key tablolar for all values.
$arr2 = array(“tablolar” => array(“aaa”,“bbb”,“ccc”,“ddd”,“eee”,“fff”,“ggg”)); … continuing 100, 200, 250 values

You can write a code sample for arr2?
The array will go as POST

Sponsor our Newsletter | Privacy Policy | Terms of Service