I found this great post here: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/ that explains how to make a POST request with php, no curl needed.

This is very convinient in many situations.

For example I wanted to get the pagerank of some page for some project I am working on.

Getting pagerank is hard, you have to know datacenter ips find a code that is working etc. With that, I can just use some online pagerank check tool. These tools usually are POST with captchas. Some don’t have captha. I found one of those, and so I needed to make the POST request from PHP then get the data.

So the code is:

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;
}

That is pretty forward. You can use custom headers too, in case you want to change the User-Agent or something.

$url is the post script url,

$data is the data variable. That one is like GET parametrs. To fix them see the source code of the POST page.

If you need a smart way to do that, download http headers firefox plugin, open it, make a post with your browser, then copy what is under Content-Length. An example is this:

textfield=test&Submit=Search