Saturday, January 5, 2013

send data post using curl php example

create test.php pastbelow code
<?php
//set POST variables
$url = 'http://127.0.0.1/test/test_2.php';
$data = array( 'username' => 'bikash','password' => '123456');
//url-ify the data for the POST
foreach($data as $key=>$value) { $logininfo.= $key.'='.$value.'&'; }
rtrim($logininfo, '&');
//open connection
$ch = curl_init();
//set the url, number of POST vars, POST data
curl_setopt($ch,CURLOPT_URL, $url);
curl_setopt($ch,CURLOPT_POST, count($data));
curl_setopt($ch,CURLOPT_POSTFIELDS, $logininfo);

//execute post
$result = curl_exec($ch);

//close connection
curl_close($ch);
?>
############create data recive page#############################
create test_2.php page below code

<?php

$username=$_POST['username'];
$password=$_POST['password'];

if($username=='bikash'){
echo "succes";
}else{
echo "fail";
}

?>

No comments:

Post a Comment