Skip to content

Instantly share code, notes, and snippets.

@jarontai
Created April 16, 2014 02:06
Show Gist options
  • Save jarontai/10798096 to your computer and use it in GitHub Desktop.
Save jarontai/10798096 to your computer and use it in GitHub Desktop.
php curl post
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);
}
$data = array(
"name" => "jaron",
"website" => "http://github.com",
"id" => "jaron"
);
post_to_url("http://yoursite.com/post-to-page.php", $data);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment