Advertisement
FathurFreakz

API WHMCS

Aug 24th, 2014
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.14 KB | None | 0 0
  1. <?php
  2. class api_whmcs {
  3.  var $url;
  4.  var $username;
  5.  var $password;
  6.  var $result;
  7.  
  8.  public function __construct($url,$username,$password){
  9.     if(substr($url,0,7) != "http://") $this->url = "http://".$url."/includes/api.php"; else $this->url = $url."/includes/api.php";
  10.     $this->username = $username;
  11.     $this->password = md5($password);
  12.  }
  13.  
  14.   public function post($postfields){
  15.     $postfields["username"] = $this->username;
  16.     $postfields["password"] = $this->password;
  17.     $ch = curl_init();
  18.     curl_setopt($ch, CURLOPT_URL, $this->url);
  19.     curl_setopt($ch, CURLOPT_POST, 1);
  20.     curl_setopt($ch, CURLOPT_TIMEOUT, 100);
  21.     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  22.     curl_setopt($ch, CURLOPT_POSTFIELDS, $postfields);
  23.     $data = curl_exec($ch);
  24.     curl_close($ch);
  25.     $data = explode(";",$data);
  26.     foreach ($data AS $temp) {
  27.         $temp = explode("=",$temp);
  28.         $results[$temp[0]] = $temp[1];
  29.     }
  30.     $this->result['result'] = $results["result"];
  31.     $this->result['message'] = $results["message"]
  32.  }
  33.  
  34.  public function query($command){
  35.     if(is_array($command)){
  36.         foreach($command as $query){
  37.             $this->post($query);
  38.         }
  39.     } else {
  40.         $this->post($query);
  41.     }
  42.  }
  43. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement