HTTP POST by PHP without CURL

source: http://wezfurlong.org/blog/2006/nov/http-post-from-php-without-curl/

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

PHP Curl Digest

<?php

class curl
{
    var $channel ;

    function curl(  )
    {
        $this->channel = curl_init( );
        // you might want the headers for http codes
        curl_setopt( $this->channel, CURLOPT_HEADER, true );
        // you may need to set the http useragent for curl to operate as
        curl_setopt( $this->channel, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
        // you wanna follow stuff like meta and location headers
        curl_setopt( $this->channel, CURLOPT_FOLLOWLOCATION, true );
        // you want all the data back to test it for errors
        curl_setopt( $this->channel, CURLOPT_RETURNTRANSFER, true );
        // probably unecessary, but cookies may be needed to
        curl_setopt( $this->channel, CURLOPT_COOKIEJAR, 'cookie.txt');
        // as above
        curl_setopt( $this->channel, CURLOPT_COOKIEFILE, 'cookie.txt');    
    }
    function makeRequest( $method, $url, $vars )
    {
        // if the $vars are in an array then turn them into a usable string
        if( is_array( $vars ) ):
            $vars = implode( '&', $vars );
        endif;

        // setup the url to post / get from / to
        curl_setopt( $this->channel, CURLOPT_URL, $url );
        // the actual post bit
        if ( strtolower( $method ) == 'post' ) :
            curl_setopt( $this->channel, CURLOPT_POST, true );
            curl_setopt( $this->channel, CURLOPT_POSTFIELDS, $vars );
        endif;
        // return data
        return curl_exec( $this->channel );
    }
}

$curl = new curl( );
// you should not execute both of these, but either way works
echo $curl->makeRequest( 'post', 'http://yourdomain.com/path/to/php.php', 'message=my message goes here' );
echo $curl->makeRequest( 'post', 'http://yourdomain.com/path/to/php.php', array('message=my message goes here', 'type=text') );
?>