Last active
October 1, 2015 13:25
-
-
Save probil/cf440ec3e866e3aa3175 to your computer and use it in GitHub Desktop.
Function send POST or GET request with data to any url
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
/** | |
* Function send GET request to server | |
* @param $request_url string Server url | |
* @param $data_array array Assoc array with data | |
* @return bool Status | |
*/ | |
function sendRequest($request_url,$data_array){ | |
// use key 'http' even if you send the request to https://... | |
$options = array( | |
'http' => array( | |
'header' => "Content-type: application/x-www-form-urlencoded\r\n", | |
'method' => 'GET', | |
'content' => http_build_query($data_array), | |
), | |
); | |
$context = stream_context_create($options); | |
$result = file_get_contents($request_url, false, $context); | |
return $result!== false; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment