Skip to content

Instantly share code, notes, and snippets.

@UziTech
Last active August 29, 2015 14:06
Show Gist options
  • Save UziTech/550234dc74352dc8ded4 to your computer and use it in GitHub Desktop.
Save UziTech/550234dc74352dc8ded4 to your computer and use it in GitHub Desktop.
Send POST request to a webpage from php and return the response
<?php
/**
* Author: Tony Brix, http://tonybrix.info
*
* Send POST request to a webpage from php and return the response.
* @param string $url The url of the webpage you would like to send the request to.
* @param array $data The post data to send with the request.
* @return string The response of the request
*/
function sendPost($url, $data) {
$data_string = http_build_query($data);
$opts = array("http" =>
array(
"method" => "POST",
"header" => "Content-Type: application/x-www-form-urlencoded",
"content" => $data_string
)
);
$result = file_get_contents($url, false, stream_context_create($opts));
return $result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment