Last active
August 29, 2015 14:06
-
-
Save UziTech/550234dc74352dc8ded4 to your computer and use it in GitHub Desktop.
Send POST request to a webpage from php and return the response
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
<?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