Library for API PHP
<?php
define('HAPI_URL','https://admin.hosting90.eu/api');
define('HAPI_USE_CURL', true);
define('UID', 0);
define('PASSWORD', 'password');
class HostingApi
{
private $sid;
function __construct()
{
$this->sid = null;
}
function __call($name, $params)
{
$url = HAPI_URL.'/'.$name.'?reply=json';
if (count($params)) {
if (count($params) < 1 || count($params) > 2 || !is_array($params[0])) {
return false;
}
foreach ($params[0] as $key => $value) {
$url .= '&'.urlencode($key).'='.urlencode((string)$value);
}
}
if ($this->sid) {
$url .= '&sid='.$this->sid;
}
if (HAPI_USE_CURL) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
if(count($params) == 2) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $params[1]);
}
$text = curl_exec($ch);
curl_close($ch);
} else {
$text = file_get_contents($url);
}
$ret = json_decode($text);
if (is_object($ret) && isset($ret->reply)) {
return $ret->reply;
} else {
return false;
}
}
function login($uid, $password)
{
$ret = $this->__call('login', array(array(), array('uid' => $uid, 'password' => $password)));
if ($ret && $ret->status->code == 0) {
$this->sid = $ret->sid;
return true;
} else {
return false;
}
}
}