Skip to content

Instantly share code, notes, and snippets.

@DylanCodeCabin
Created October 7, 2016 13:12
Show Gist options
  • Save DylanCodeCabin/d866ea844ec20a5e41e3a13b8a2f5acd to your computer and use it in GitHub Desktop.
Save DylanCodeCabin/d866ea844ec20a5e41e3a13b8a2f5acd to your computer and use it in GitHub Desktop.
Make a simple post request without the use of curl
<?php
function quick_post_no_curl($url, $form_data){
// 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' => 'POST',
'content' => http_build_query($form_data)
)
);
$context = stream_context_create($options);
$result = file_get_contents($url, false, $context);
if ($result === FALSE) {
return false;
} else {
return $result;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment