首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Directadmin CMD_API_SHOW_DOMAINS域阵列

Directadmin CMD_API_SHOW_DOMAINS域阵列
EN

Stack Overflow用户
提问于 2016-07-27 02:04:47
回答 1查看 927关注 0票数 1

我想集成Directadmin的CMD_API_SHOW_DOMAINS函数,但是我不知道如何分解返回的数组。

目前,我使用的是以下代码:

代码语言:javascript
复制
<?
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

?>

我收到了这封信:

代码语言:javascript
复制
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,所以接口会返回结果:

代码语言:javascript
复制
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 (function CMD_API_SHOW_DOMAINS)

底层↓↓↓中的规范

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

发布于 2020-08-14 21:24:01

您希望在foreach循环中获得结果,在该循环中,您将结果定义为键、值对。

这是我用来做同样事情的代码:

代码语言:javascript
复制
$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;
            };  
            
        };  

您将需要使用字符串replace _。在结果上,因为域值在扩展中带有下划线而不是句点。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38596952

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档