Showing posts with label How to pass variables via PHP CURL. Show all posts
Showing posts with label How to pass variables via PHP CURL. Show all posts

Friday 5 February 2016

How to pass variables via PHP CURL

How to pass variables via PHP CURL

$message="Thank you";
$phone = 123456789;
$url = 'http://example.com';


$fields = array('phone'=>$phone,'source'=>'test','message'=>$message);
$fields_string='';


foreach($fields as $key=>$value) {  $fields_string .= $key.'='.$value.'&'; }
rtrim($fields_string, '&');


$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($fields));
curl_setopt($ch,CURLOPT_POSTFIELDS, $fields_string);
$result = curl_exec($ch);
curl_close($ch);