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:
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
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


An easier way to do this – load() function. With and without curl
Both are almost same , i think
Hi,
I’s very compact and working solution so a big thanx to you.
I thing arguments need explanation. Cause I need to unzip the file. For copy&pasters:
$data can be prepared with use of http_build_query. give assoc array. url ;I used http://domain.com/file.php rest resides in $data.
Mr Sajith Your function is not function a kind of library I guess. It could be complete for a project but for a small posts I like this one.
Hi,
I’m trying to use the above code and it keeps throwing the first exception.. do you know why, or how i can fix it ?
10x.
Looks like it was stolen (w/out reference) from : http://netevil.org/blog/2006/nov/http-post-from-php-without-curl
(yes, 2006)
Plagarism FTW!
Nice Farzanegan, i never mention anywhere that i did the code. It is for those who seeks for code. And moreover, i never made my own PHP from home. I got the php codes and documentation from php.net. Should I mention all these in my all project ?
I try to do the same, “why reinvent the wheel”
But you could have let a link to original source
thank you
Please help me to authenticate zabbix monitoring url with any possible function……to avoiding repeated login…..