我想集成 Directadmin CMD_API_SHOW_DOMAINS 函数,但我不明白如何分解返回的数组。
目前,我正在使用以下代码:
<?
include("httpsocket.php");
$sock = new HTTPSocket;
$sock->connect('myip',2222);
$sock->set_login('admin', 'pass123');
$user= "username"; //user which own printed domains.
$sock->query('/CMD_API_SHOW_USER_DOMAINS?user='.$user);
$domains = $sock->fetch_parsed_body();
print_r ($domains); // printing fetched array
?>
我收到这个:
Array ( [rara_com] => 0.000000:unlimited:0.0664062:0.000000:0:no:unlimited:OFF:ON:ON )
对于具有 rara.com 域的用户 x。此 api 显示所有域,因此页面中可能显示更多数组,例如用户 Y 有 3 个域。google.com、yahoo.com、stackoverflow.com,所以 api 会返回结果:
Array ( [google_com] => 0.000000:unlimited:0.0664062:0.000000:0:no:unlimited:OFF:ON:ON ) Array ( [yahoo_com] => 0.000000:unlimited:0.0664062:0.000000:0:no:unlimited:OFF:ON:ON ) Array ( [stackoverflow_com] => 0.000000:unlimited:0.0664062:0.000000:0:no:unlimited:OFF:ON:ON )
如何爆炸这些阵列?这对我来说真的很头疼。我只需要第一个元素(域名,例如 rara_com、google_com)
Directadmin api https://www.directadmin.com/api.php(函数CMD_API_SHOW_DOMAINS)
规格在底部↓↓↓</p>
Get User Domains:
Function Retrieve the list of domains owned by the user, and some basic stats
Command CMD_API_SHOW_USER_DOMAINS
Method GET
Success Returns url encoded array
Failure Returns error=1
Form Values:
Name Value
user Username of the user for which you wish to view the stats
Array Returns Values
Name Value
domain.com Colon speparated list with domain information: eg. 6757.4:unlimited:0.000356674:93.5:2:no:unlimited:ON:ON:ON where the data is bandwidth used:bandwidth limit:disk usage for the domain:log usage for the domain:# of subdomains:suspended:quota:ssl:cgi:php
( domain2.com ... ) Same as domain.com, one entry for each domain