This Tutorial Has Been Viewed 9,968 Times.
VN:F [1.9.20_1166]
Rating: 6.3/10 (3 votes cast)

Hello guys, Glad to say that this is my 100th Post.The below code will help you how to post data from your webite to another website using cUrl in PHP

<?php
$urltopost = "http://mywebsite.com/post.php";
$datatopost = array ("firstname" => "James",
"lastname" => "Anderson","email" => "admin@mistonline.in",);
 $ch = curl_init ($urltopost);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$returndata = curl_exec ($ch);
?>

$urltopost
The url where you want to post your data to

$datatopost
The post data as an associative array. The keys are the post variables

$ch = curl_init ($urltopost);
Initializes cURL

curl_setopt ($ch, CURLOPT_POST, true);
Tells cURL that we want to send post data

curl_setopt ($ch, CURLOPT_POSTFIELDS, $datatopost);
Tells cURL what are post data is

curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
Tells cURL to return the output of the post

$returndata = curl_exec ($ch);
Executes the cURL and saves theoutput in $returndata

Thanks a lot http://coderscult.com

VN:F [1.9.20_1166]
Rating: 6.3/10 (3 votes cast)
Post Data To Another Website Using cURL In PHP, 6.3 out of 10 based on 3 ratings


coded by nessus
Categories: cUrl, PHP, Tools

Leave a Reply