Example Usage

username and password are mandatory for all operations.

<?php

function mikrovps_GetIP() {
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_URL, "http://www.whmcs.com/getip/" );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        $contents = curl_exec( $ch );
        curl_close( $ch );
        return $contents;
}

function mikrovps_SendCommand($postfields, $method, $nodecode = false) {

        $url = $API_URL;

        $ch = curl_init();

        if ($method == "GET") {
                $url .= "?";
                foreach ($postfields as $field => $data) {
                        $url .= "" . $field . "=" . rawurlencode( $data ) . "&";
                }

                $url = substr( $url, 0, 0 - 1 );
                $postfields['url'] = $url;
        }
        else {
                $postfield = "";
                foreach ($postfields as $field => $data) {
                        $postfield .= "" . $field . "=" . $data . "&";
                }

                $postfield = substr( $postfield, 0, 0 - 1 );
                curl_setopt( $ch, CURLOPT_POST, 1 );
                curl_setopt( $ch, CURLOPT_POSTFIELDS, $postfield );
        }
        curl_setopt( $ch, CURLOPT_URL, $url );
        curl_setopt( $ch, CURLOPT_TIMEOUT, 100 );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYPEER, 0 );
        curl_setopt( $ch, CURLOPT_SSL_VERIFYHOST, 0 );
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER, 1 );
        $data = curl_exec( $ch );

        if (curl_errno( $ch )) {
                $ip = mikrovps_GetIP();
                $ip2 = (isset( $_SERVER['SERVER_ADDR'] ) ? $_SERVER['SERVER_ADDR'] : $_SERVER['LOCAL_ADDR']);
                $result['response']['status'] = "ERROR";
                $result['response']['message'] = "CURL Error: " . curl_errno( $ch ) . " - " . curl_error( $ch ) . ( " (IP: " . $ip . " & " . $ip2 . ")" );
        }
        else {
                if ( $nodecode ) {
                        $result = $data;
                }
                else {
                        $result = json_decode( $data, true );
                }
        }

        curl_close( $ch );
        return $result;
}


$postfields = array();
$postfields['responsetype'] = "json"; // It can be JSON or XML
$postfields['username'] = 'USERNAME';
$postfields['password'] = 'PASSWORD';
$postfields['action'] = 'ACTION';
$result = mikrovps_SendCommand($postfields, "POST", false );
  • 3 Korisnici koji smatraju članak korisnim
Je li Vam ovaj odgovor pomogao?

Vezani članci

WHMCS modules

We are providing WHMCS module (based on our API) for some type of product: Domain registration...