如何将变量放入curl中的数组中

(I apologize in advance for my English at the carpet level)

I want send request by curl, the code i use normal work. When i change my code adding variable in to array, code working, also dont set this cookie.

i tried set:

'Cookie: ssid=.$input; path=/; domain=example.com;',

and

'Cookie: "ssid=".$input; path=/; domain=example.com;',

and

'Cookie: 'ssid='.$input; path=/; domain=example.com;',

this is all code

$ch4=curl_init("https://example.com/");
curl_setopt_array($ch4,array(
        CURLOPT_USERAGENT=>' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
        CURLOPT_ENCODING=>'gzip, deflate',
        CURLOPT_HTTPHEADER=>array(
                'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'Accept-Language: en-US,en;q=0.5',
                'Accept-Encoding: gzip, deflate',
                'Connection: keep-alive',
                'Upgrade-Insecure-Requests: 1',
                'Cookie: ssid=.$input; path=/; domain=example.com;',
        ),
));

i want this cake read from variable ($input)

Assign a variable to particular array

$myArr['message']['to_recipients'] = $emails;

then set on curl

$ch = curl_init();
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));

you can send the cookie manually along with the cookie from the file(using cookie-file option). For example:

//SEND DATA VARIABLE IN JSON ENCODED FORMAT
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $myArr ));

// sending manually set cookie
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Cookie: test=cookie"));

// sending cookies from file
curl_setopt($ch, CURLOPT_COOKIEFILE, $ckfile);

And for you code you have used php variable in cookie as string so you have to update your script like given below.

$ch4=curl_init("https://example.com/");
curl_setopt_array($ch4,array(
        CURLOPT_USERAGENT=>' Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/73.0.3683.103 Safari/537.36',
        CURLOPT_ENCODING=>'gzip, deflate',
        CURLOPT_HTTPHEADER=>array(
                'Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
                'Accept-Language: en-US,en;q=0.5',
                'Accept-Encoding: gzip, deflate',
                'Connection: keep-alive',
                'Upgrade-Insecure-Requests: 1',
                'Cookie: ssid='.$input.'; path=/; domain=example.com;',
        ),
));