Reputation: 55
Please can someone help me? I'm using the WHM API to list the users, these users searching the area, but I can not make it work. I have tried, but not work. how to search the User by the domain???
example:
$domain = 'mydomain.com';
$accounts = $whm->listaccts($domain);
foreach ($accounts as $ac){
$userCp = $ac["user"];
}
echo $userCp;
Function:
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;
}
I've tried several ways, but does not work. Thank you so much for your attention
Renata
Upvotes: 0
Views: 1161
Reputation: 377
An account can be searched by username as below:-
// 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
}
Upvotes: 0