The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Need help understanding basics of XML-API for PHP

Discussion in 'cPanel Developers' started by marcelg, Oct 9, 2012.

  1. marcelg

    marcelg Member

    Joined:
    Nov 8, 2007
    Messages:
    5
    Likes Received:
    0
    Trophy Points:
    1
    Hello,

    I have spent lots of time with this and think it's time to ask for some advice.

    I have downloaded the xmlapi.php file and have it included in my scrpt.

    My script specifies the server IP and authenticates via the $xmlapi->hash_auth fine.

    I am just trying to run one command to list accounts: print $xmlapi->listaccts();

    This gives me a blank screen and when I "View Source" I see lots of blank lines. If I comment out the print $xmlapi->listaccts() the blank lines don't appear in the source.

    I checked my error_log with $xmlapi->set_debug(1) and found lots of data going in there.

    error_log shows my Authorization Header followed by any entry starting with RESPONSE: \n <listaccts>\n and it goes on to output all the information I'm trying to get.

    How do I access this information and have it display on my HTML page instead of the error log? I'm guessing I'm missing something here. Please give me some advice.
     
  2. cPanelDavidN

    cPanelDavidN Integration Developer
    Staff Member

    Joined:
    Dec 17, 2009
    Messages:
    571
    Likes Received:
    1
    Trophy Points:
    18
    Location:
    Houston, TX
    cPanel Access Level:
    Root Administrator
    listaccts(), which calls xmlapi_query() internally, returns a data structure (unless you specify 'json' in a prior invocation of set_output())

    PHP data structures, like arrays and objects, should not be provided as an argument to the print directive. If you know that you have an array, you can use print_r(). If you're want to get an idea of what a variable is or what it contains, you're better served by using var_dump() to simply dump the variable; var_dump() will provide additional markup so that you can understand the internal structure and value of the variable's contents.

    -DavidN
     
Loading...

Share This Page