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


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

        // 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 );
        // 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', '', 'message=my message goes here' );
echo $curl->makeRequest( 'post', '', array('message=my message goes here', 'type=text') );

Cpanel API Digest

Hello every one! Let’s eat some tricks…


Cpanel Security token

“Security token” URLs were added in cPanel & WHM 11.25 as a security measure, and they were enabled by default in version 11.28. They help combat a common type of attack called a Cross-Site Request Forgery (XSRF).

So, what does a “security token” look like? Take, for example, this URL:

With security tokens enabled, this would become:

The token is available in the environment variable ‘cp_security_token’.

my $APIurl = "$ENV{'cp_security_token'}/xml-api/$url";

Find more information click here.