我想集成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)
底部的规格↓↓↓
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
答案 0 :(得分:0)
您希望在foreach循环中获得结果,在其中将结果定义为键,值对。
这是我用来执行相同操作的代码:
$sock = new HTTPSocket;
$sock->connect("ssl://" . $server,2222);
$sock->set_login('foo','bar');
$sock->query('/CMD_API_SHOW_USER_DOMAINS?user=' . $user);
$result = $sock->fetch_parsed_body();
if(empty($result))
{
echo "Problem connecting to server: " . $server;
}
else
{
foreach($result as $key => $value)
{
echo 'Domain : ' . $key;
};
};
您需要将_替换为字符串。域值带有下划线而不是扩展名中的句点。