Skip to content

Instantly share code, notes, and snippets.

@UziTech
Last active Aug 29, 2015
Embed
What would you like to do?
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