Hallo! Selamat Datang di Marketplace produk digital, Freelancer terbaik di indonesia (67507 Members, 783 Products, 5291 Topic, 12956 Comments)

Buat Variabel di PHP Curl

Dibuat
Login Terakhir 2 Bulan lalu,
Telah Dilihat 1172 Kali
dwi vindyanto Mengatakan : Sultan Account
  1. Assalamualaikum Warahmatullahi Wabarakatuh...
  2. Minta tolong solusinya gan
  3. Bikin variabel di sini g bisa..
  4. Terima kasih sebelumnya
  5.  
  6. $curl = curl_init();
  7. $username = "dingtangtong"
  8. CURLOPT_URL => 'http://wa.domain.id/apiv1/sendText',
  9. CURLOPT_RETURNTRANSFER => true,
  10. CURLOPT_ENCODING => '',
  11. CURLOPT_MAXREDIRS => 10,
  12. CURLOPT_TIMEOUT => 0,
  13. CURLOPT_FOLLOWLOCATION => true,
  14. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  15. CURLOPT_CUSTOMREQUEST => 'GET',
  16. CURLOPT_POSTFIELDS =>'{
  17. "sender":"'$username'",
  18. "token":"zbequwdio456",
  19. "type":"image",
  20. "number":"628113004277",
  21. "message":"Tess Kirim WA by API",
  22. "url":"http://wa.domain.id/img/brosur.jpg"
  23. }',
  24. CURLOPT_HTTPHEADER => array(
  25. 'Content-Type: application/json'
  26. ),
  27. ));
  28.  
  29. $response = curl_exec($curl);
  30.  
  31. curl_close($curl);
  32. echo $response;

Ada 4 Jawaban

PHPMU.COM Support
commented on 30 Des 2022 21:43:25
  1. Assalamualaikum,.. cukup tulis tanpa kutip satu atau dua,
  2. jadi seperti ini : "sender":$username,
PHPMU.COM Support
commented on 30 Des 2022 21:44:09
  1. atau begini harusnya juga bisa : "sender":"$username",
Dahry Dev
commented on 03 Jan 2023 21:28:06
  1. Waalaikumsalam.
  2.  
  3. "sender":"'. $username.'",
Yusfi Cahyadi
commented on 22 Feb 2023 10:44:26
  1. Assalamualaikum,..
  2.  
  3. Klo boleh saran.. lebih baik disimpan didalam array lalu convert ke json menggunakan json_encode untuk postfields-nya.
  4.  
  5. $curl = curl_init();
  6. $username = "dingtangtong"
  7. $postfields = array(
  8. 'sender' => $username,
  9. 'token' => 'zbequwdio456',
  10. 'type' => 'image',
  11. 'number' => '628113004277',
  12. 'message' => 'Tess Kirim WA by API',
  13. 'url' => 'http://wa.domain.id/img/brosur.jpg'
  14. );
  15. CURLOPT_URL => 'http://wa.domain.id/apiv1/sendText',
  16. CURLOPT_RETURNTRANSFER => true,
  17. CURLOPT_ENCODING => '',
  18. CURLOPT_MAXREDIRS => 10,
  19. CURLOPT_TIMEOUT => 0,
  20. CURLOPT_FOLLOWLOCATION => true,
  21. CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  22. CURLOPT_CUSTOMREQUEST => 'GET',
  23. CURLOPT_POSTFIELDS => json_encode($postfields),
  24. CURLOPT_HTTPHEADER => array(
  25. 'Content-Type: application/json'
  26. ),
  27. ));
  28.  
  29. $response = curl_exec($curl);
  30.  
  31. curl_close($curl);
  32. echo $response;
Maaf, Untuk Memberikan Komentar Anda Harus Login !!!