PHP code to access php webservice

  PHP

<?php

function post_to_url($url, $data) {
$fields = ”;
foreach ($data as $key => $value) {
$fields .= $key . ‘=’ . $value . ‘&’;
}
rtrim($fields, ‘&’);

$post = curl_init();

curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($post);
curl_close($post);
return $result;
}

$data = array(“mobile1″=>”1111111″,”mobile2″=>”123456789”,
“fname”=>”Bill”,”lname”=>”Clinton”,”dstatus”=>”wait”,”rstatus”=>”old”,
“server_ipadr”=>”192.168.1.120″,”trans_id”=>”5″,”time_of_meet”=>”15min”,”server_id”=>”101″);

$surl = ‘http://192.168.1.120/test1/signup1.php’;
echo post_to_url($surl, $data);
?>

LEAVE A COMMENT