2016-05-27 67 views
0

請有人可以幫助我嗎? 我正在使用WHM API列出用戶,這些用戶正在搜索該區域,但我無法使其工作。我嘗試過,但沒有工作。 如何通過域名搜索用戶?whm API - listaccts api搜索用戶通過域名在PHP

例如:

$domain = 'mydomain.com'; 

$accounts = $whm->listaccts($domain); 

foreach ($accounts as $ac){ 
     $userCp = $ac["user"]; 
} 

echo $userCp; 

功能:

function listaccts() 
{ 
    //connect using prpoer xml api address 
    $this->connect('/xml-api/listaccts'); 
    //get the output 
    $xmlstr=$this->getOutput(); 
    if($xmlstr=='') 
    { 
     $this->errors[]='No output.'; 
     return false; 
    } 
    //disconnect 
    $this->disconnect(); 

    $xml = new DOMDocument(); 
    $xml->loadXML($xmlstr); 

    // statement block to get the elements of the xml document 
    $list = $xml->getElementsByTagName('user'); 
    $i=0; 
    foreach ($list AS $element) 
    { 
     foreach ($element->childNodes AS $item) 
     { 
      $result[$i]['user']=$item->nodeValue; 
      $i++; 
     } 
    } 

    $list = $xml->getElementsByTagName('domain'); 
    $i=0; 
    foreach ($list AS $element) 
    { 
     foreach ($element->childNodes AS $item) 
     { 
      $result[$i]['domain']=$item->nodeValue; 
      $i++; 
     } 
    } 

    $list = $xml->getElementsByTagName('plan'); 
    $i=0; 
    foreach ($list AS $element) 
    { 
     foreach ($element->childNodes AS $item) 
     { 
      $result[$i]['package']=$item->nodeValue; 
      $i++; 
     } 
    } 

    $list = $xml->getElementsByTagName('unix_startdate'); 
    $i=0; 
    foreach ($list AS $element) 
    { 
     foreach ($element->childNodes AS $item) 
     { 
      $result[$i]['start_date']=$item->nodeValue; 
      $i++; 
     } 
    } 

    //return the result array 
    return $result; 
} 

我嘗試了多種方法,但不起作用。 非常感謝你的關注

雷娜塔

回答

0

一個帳戶可以通過用戶名,如下搜索: -

// server_domain it will be your whm login url 

// $rootusername will be whm username 

// $rootpassword will be WHM password 

// include WHM/cpanel files here 

$xmlapi = new \xmlapi_latest($server_domain); 
//checking authentication of the WHM 
$xmlapi->password_auth($rootUsername,$rootPassword); 

$result = json_decode($xmlapi->accountsummary($cpanel->cred_username)); 

if(isset($result->status) && $result->status==1){ 
    // domain will be 
    echo $result->acct[0]->domain 
}