[Resolved] Use api 2 call to get user information and convert it to php variable
Hi,
I'm currently trying to get user information via whm's xmlapi php class and convert the information into php variables. My code looks like this
[PHP]
//Ive deleted any information that could be used to login to my server
$server_username ='root';
$ip = '0.0.0.0';
$root_hash = 'hash goes here';
//server ip is passed
$xmlapi = new xmlapi($ip);
//server username normally root and hash is passed
$xmlapi->hash_auth($server_username,$root_hash);
$whm_username = 'some_user';
$xmlapi->set_debug(1);
$args = array('display' => 'bandwidthusage');
$xmlapi->api2_query($whm_username, 'StatsBar', 'stat', $args);
[/PHP]
thank you in advance for your assistance and suggestions
David
-
Just set the result to a variable: hash_auth($server_username, $root_hash); $xmlapi->set_debug(0); $args = array('display' => 'bandwidthusage'); $result = $xmlapi->api2_query($cpanel_username, 'StatsBar', 'stat', $args); print_r($result);
This will return:[SimpleXMLElement Object ( [apiversion] => 2 [data] => SimpleXMLElement Object ( [name] => bandwidthusage [_count] => 8.97 [_max] => unlimited [_maxed] => 0 [count] => 8.97 [feature] => bandwidth [id] => bandwidthusage [item] => Monthly Bandwidth Transfer [langkey] => INDXBandwidth [max] => unlimited [module] => Stats [normalized] => 1 [percent] => 0 [percent10] => 0 [percent20] => 0 [percent5] => 0 [units] => MB [zeroisunlimited] => 1 ) [event] => SimpleXMLElement Object ( [result] => 1 ) [func] => stat [module] => StatsBar )
Then all you have to do is pull out the variables you want. For example, to get the value of _max in the above result:$max = $result->data->_max;
Will return:unlimited
Hope this helps.0 -
Hello :) The previous post seems to accurately answer your question so I am marking this thread as resolved. Feel free to update this thread if you have any additional questions. Thank you. 0
Please sign in to leave a comment.
Comments
2 comments