PHP post without curl
You can simulate the post method using php without the help of curl library.
download full source code:
![]()
See the code below:
function do_post_request($url, $data, $optional_headers = null) {
$params = array('http' =>; array('method' =>; 'POST',
'content' =>; $data
));
if ($optional_headers !== null) {
$params['http']['header'] = $optional_headers;
}
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp) {
throw new Exception("Problem with $url, $php_errormsg");
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from $url, $php_errormsg");
}
return $response;
}
?>
Download the full source code from post_without_curl.zip
|
|
|
|
If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!
Stumble Reviews
Plugin powered by StumbleCult2 Responses to “PHP post without curl”
-
Binny V A Says:
April 4th, 2008 at 11:44 amAn easier way to do this - load() function. With and without curl
-
Sajith M.R Says:
April 4th, 2008 at 12:04 pmBoth are almost same , i think


Review on — April 4, 2008, 5:32 pm