Post Data to Remote server using curl

Using curl you can post data to remote server . You have to place all the details to send in a array .

 

[cc lang=”php”]

// URL to post data
$url = “http://www.publicvoidlife.com/curl.php”;
// Data to send

$data = array(
“name” =>  “Jijin”,
“country” => “IN”,
)

$postData = ”;
foreach($data as $k => $v)
{
$postData .= $k.’=’.$v.’&’;
}
rtrim($postData, ‘&’);

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

[/cc]

The data can be fetched by GET method
For eg:
$_GET[‘name’]

 

 

Jijin P

Developer at Devzstudio

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *