Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    Member
    Join Date
    May 2007
    Posts
    23

    Default Select only necessary information

    Hello

    I am new to this XML- API calls. Never used before. I did a couple of searches here before posting. Gathered some information, but need lot more.

    Here is the code what I am using for my first need.
    Code:
    <?php
    
    $host = "localhost";
    $user = "root";
    $accesshash = "[ACCESSHASH]";
    
    header( "Content-type: application/xml" );
    
    $request = "/xml-api/accountsummary?user=${user}";
    
    $cleanaccesshash = preg_replace("'(\r|\n)'","",$accesshash);
    // Change 'root' to reseller username as required
    $authstr = "root:" . $cleanaccesshash;
    $cpanelaccterr = "";
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $curlheaders[0] = "Authorization: WHM $authstr";
    curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
    $data=curl_exec ($ch);
    curl_close ($ch);
    
    echo $data;
    
    ?>


    I never tried anything with XML files, So I dont know how to arrage the result.
    I am using PHP for my coding.


    Here is the sample result I am getting.


    Code:
    <accountsummary>
    −
    <acct>
    <disklimit>unlimited</disklimit>
    <diskused>581M</diskused>
    <domain>domain.com</domain>
    <email>*unknown*</email>
    <ip>IP address</ip>
    <owner>username</owner>
    <partition>home</partition>
    <plan>package_name</plan>
    <startdate>07 Aug 25 02:55</startdate>
    <suspended>0</suspended>
    <suspendreason>not suspended</suspendreason>
    <theme>xpevolution</theme>
    <unix_startdate>1188028514</unix_startdate>
    <user>user</user>
    </acct>
    <status>1</status>
    <statusmsg>Ok</statusmsg>
    </accountsummary>



    I just want to display the username as well as domain name using my php code.

    like

    $username = xml_array(<username>)

    echo $username

    But I am not sure how can I extract the username form the above output using php

    Anyone can help me ?

  2. #2
    Member
    Join Date
    May 2007
    Posts
    23

    Default

    Anybody here for a help ?

  3. #3
    Technical Product Specialist cPanelDavidG's Avatar
    Join Date
    Nov 2006
    Location
    Houston, TX
    Posts
    11,189
    cPanel/Enkompass Access Level

    Root Administrator

    Default

    I'm a big fan of using SimpleXML in PHP5, especially since I can run xpath queries.

    Here's some relevant documentation:

    http://us.php.net/manual/en/function...oad-string.php

    http://us.php.net/manual/en/function...ment-xpath.php

  4. #4
    Member
    Join Date
    Nov 2008
    Posts
    6

    Default

    Quote Originally Posted by vivekvsist View Post
    Hello

    I am new to this XML- API calls. Never used before. I did a couple of searches here before posting. Gathered some information, but need lot more.

    Here is the code what I am using for my first need.
    Code:
    <?php
    
    $host = "localhost";
    $user = "root";
    $accesshash = "[ACCESSHASH]";
    
    header( "Content-type: application/xml" );
    
    $request = "/xml-api/accountsummary?user=${user}";
    
    $cleanaccesshash = preg_replace("'(\r|\n)'","",$accesshash);
    // Change 'root' to reseller username as required
    $authstr = "root:" . $cleanaccesshash;
    $cpanelaccterr = "";
    
    $ch = curl_init();
    
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,0);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,0);
    curl_setopt($ch, CURLOPT_URL, "https://${host}:2087" . $request);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    $curlheaders[0] = "Authorization: WHM $authstr";
    curl_setopt($ch,CURLOPT_HTTPHEADER,$curlheaders);
    $data=curl_exec ($ch);
    curl_close ($ch);
    
    echo $data;
    
    ?>


    I never tried anything with XML files, So I dont know how to arrage the result.
    I am using PHP for my coding.


    Here is the sample result I am getting.


    Code:
    <accountsummary>
    −
    <acct>
    <disklimit>unlimited</disklimit>
    <diskused>581M</diskused>
    <domain>domain.com</domain>
    <email>*unknown*</email>
    <ip>IP address</ip>
    <owner>username</owner>
    <partition>home</partition>
    <plan>package_name</plan>
    <startdate>07 Aug 25 02:55</startdate>
    <suspended>0</suspended>
    <suspendreason>not suspended</suspendreason>
    <theme>xpevolution</theme>
    <unix_startdate>1188028514</unix_startdate>
    <user>user</user>
    </acct>
    <status>1</status>
    <statusmsg>Ok</statusmsg>
    </accountsummary>



    I just want to display the username as well as domain name using my php code.

    like

    $username = xml_array(<username>)

    echo $username

    But I am not sure how can I extract the username form the above output using php

    Anyone can help me ?
    How did you get this working?

    Please Tell!

Similar Threads & Tags
Similar threads

  1. Can't select database
    By tomw in forum cPanel and WHM Discussions
    Replies: 8
    Last Post: 04-30-2009, 04:05 PM
  2. give ads to select users or under a select user
    By kistler in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 03-28-2006, 06:00 AM
  3. Select or Not Select PHP SueExec Support, that's the question...
    By Hueznar in forum cPanel and WHM Discussions
    Replies: 7
    Last Post: 06-12-2004, 09:12 AM
  4. Why is there no select all on each column
    By Donna in forum cPanel and WHM Discussions
    Replies: 2
    Last Post: 02-26-2004, 05:24 PM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube