Last active
October 14, 2022 09:19
-
-
Save ytkhs/1000074 to your computer and use it in GitHub Desktop.
a sample POST method with file_get_contents()
This file contains hidden or 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 | |
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)); | |
} | |
} |
thanks you, post very good !
And years later, still useful! Thanks.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Awesome function, by and by. Just discovered this today via Opengraph.