Skip to content

Instantly share code, notes, and snippets.

@probil
Last active October 1, 2015 13:25
Show Gist options
  • Save probil/cf440ec3e866e3aa3175 to your computer and use it in GitHub Desktop.
Save probil/cf440ec3e866e3aa3175 to your computer and use it in GitHub Desktop.
Function send POST or GET request with data to any url
/**
* 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