Skip to content

Instantly share code, notes, and snippets.

@ytkhs
Last active October 14, 2022 09:19
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ytkhs/1000074 to your computer and use it in GitHub Desktop.
Save ytkhs/1000074 to your computer and use it in GitHub Desktop.
a sample POST method with file_get_contents()
<?php
if (!function_exists('http_post_contents')) {
function http_post_contents($url, $params) {
$content = http_build_query($params, '', '&');
$header = array(
"Content-Type: application/x-www-form-urlencoded",
"Content-Length: ".strlen($content)
);
$options = array(
'http' => array(
'method' => 'POST',
'content' => $content,
'header' => implode("\r\n", $header)
)
);
return file_get_contents($url, false, stream_context_create($options));
}
}
@WASasquatch
Copy link

Awesome function, by and by. Just discovered this today via Opengraph.

@anhtuan1994
Copy link

thanks you, post very good !

@Ralpharama
Copy link

And years later, still useful! Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment