Last active
August 29, 2015 14:06
-
-
Save kruxor/3052539c7c78892c2675 to your computer and use it in GitHub Desktop.
Post back to a URL using curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function httpPost($url,$params) | |
{ | |
$postData = ''; | |
//create name value pairs seperated by & | |
foreach($params as $k => $v) | |
{ | |
$postData .= $k . '='.$v.'&'; | |
} | |
rtrim($postData, '&'); | |
$ch = curl_init(); | |
curl_setopt($ch,CURLOPT_URL,$url); | |
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); | |
curl_setopt($ch,CURLOPT_HEADER, false); | |
curl_setopt($ch, CURLOPT_POST, count($postData)); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | |
$output=curl_exec($ch); | |
curl_close($ch); | |
return $output; | |
} | |
$params = array( | |
"name" => "Ravishanker Kusuma", | |
"age" => "32", | |
"location" => "India" | |
); | |
echo httpPost("http://hayageek.com/examples/php/curl-examples/post.php",$params); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment