Created
April 16, 2014 02:06
-
-
Save jarontai/10798096 to your computer and use it in GitHub Desktop.
php curl post
This file contains hidden or 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 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