Awesome PHP
It’s strange how powerful PHP can be. There’s a legend that cURL is the only way to perform a HTTP POST with PHP, but that isn’t the truth. An extremely useful script is by using stream_context_create:
$optional_headers = null; $params = array('http' => array( 'method' => 'POST', 'content' => http_build_query(array('name' => 'my-name')))); if ($optional_headers !== null) { $params['http']['header'] = $optional_headers; } $ctx = stream_context_create($params); $fp = @fopen('http://example.com/post.php', 'rb', false, $ctx); |
Well this is only a snippet. You can change a lot this code and perform any request, but here’s a small start up. However note that this will do the same as while posting to example.com/post.php via web form!
this is just an alternative to curl, and most probably, sub-par.
You can use file_get_contents this way too.
Using fopen is not a good idea because some hosting companies disable the opening of URL with fopen for security reasons.
And to post a file how to do it ??? (ok the optional header will be multipart/form data but where to put the contentof the file to be posted )