jubba890 Posted July 11, 2014 Share Posted July 11, 2014 I am using WHMCS API and It gives me an array for the first name, last name, etc for the client information Here is the code I have so far checkLogin.php <?php session_start(); echo "ID: " . $_SESSION['clientID']; $postfields = array(); $postfields["action"] = "getclientsdetails"; $postfields["clientid"] = $_SESSION['clientID']; $postfields["stats"] = true; $postfields["responsetype"] = "xml"; echo "<br>"; include('XMLAPI.php'); ?> XMLAPI.php <?php /* *** WHMCS XML API Sample Code *** */ $url = "http://inzernettechnologies.com/billing/includes/api.php"; # URL to WHMCS API file $username = "user"; # Admin username goes here $password = "pass"; # Admin password goes here $postfields["username"] = $username; $postfields["password"] = md5($password); $query_string = ""; foreach ($postfields AS $k=>$v) $query_string .= "$k=".urlencode($v)."&"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_TIMEOUT, 30); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $query_string); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); $xml = curl_exec($ch); if (curl_error($ch) || !$xml) $xml = '<whmcsapi><result>error</result>'. '<message>Connection Error</message><curlerror>'. curl_errno($ch).' - '.curl_error($ch).'</curlerror></whmcsapi>'; curl_close($ch); $arr = whmcsapi_xml_parser($xml); # Parse XML print_r($arr); # Output XML Response as Array /* Debug Output - Uncomment if needed to troubleshoot problems echo "<textarea rows=50 cols=100>Request: ".print_r($postfields,true); echo "\nResponse: ".htmlentities($xml)."\n\nArray: ".print_r($arr,true); echo "</textarea>"; */ function whmcsapi_xml_parser($rawxml) { $xml_parser = xml_parser_create(); xml_parse_into_struct($xml_parser, $rawxml, $vals, $index); xml_parser_free($xml_parser); $params = array(); $level = array(); $alreadyused = array(); $x=0; foreach ($vals as $xml_elem) { if ($xml_elem['type'] == 'open') { if (in_array($xml_elem['tag'],$alreadyused)) { $x++; $xml_elem['tag'] = $xml_elem['tag'].$x; } $level[$xml_elem['level']] = $xml_elem['tag']; $alreadyused[] = $xml_elem['tag']; } if ($xml_elem['type'] == 'complete') { $start_level = 1; $php_stmt = '$params'; while($start_level < $xml_elem['level']) { $php_stmt .= '[$level['.$start_level.']]'; $start_level++; } $php_stmt .= '[$xml_elem[\'tag\']] = $xml_elem[\'value\'];'; @eval($php_stmt); } } return($params); } ?> It outputs: ID: 1 Array ( [WHMCSAPI] => Array ( [ACTION] => getclientsdetails [RESULT] => success [CLIENT] => Array ( [USERID] => 1 [ID] => 1 [FIRSTNAME] => Cody [LASTNAME] => Robinson [FULLNAME] => Cody Robinson [COMPANYNAME] => InZernet Technologies [EMAIL] => cody-admin@inzernettechnologies.com [ADDRESS1] => Address [ADDRESS2] => [CITY] => 11 [FULLSTATE] => Michigan [STATE] => Michigan [POSTCODE] => 11111 [COUNTRYCODE] => US [COUNTRY] => US [STATECODE] => MI [COUNTRYNAME] => United States [PHONECC] => 1 [PHONENUMBER] => 1111111111 [PHONENUMBERFORMATTED] => 11111111 [BILLINGCID] => 0 [NOTES] => [PASSWORD] => PASSWORD [TWOFAENABLED] => [CURRENCY] => 1 [DEFAULTGATEWAY] => [CCTYPE] => [CCLASTFOUR] => [SECURITYQID] => 29 [SECURITYQANS] => Rogers [GROUPID] => 0 [STATUS] => Active [CREDIT] => 0.00 [TAXEXEMPT] => [LATEFEEOVERIDE] => [OVERIDEDUENOTICES] => [SEPARATEINVOICES] => [DISABLEAUTOCC] => [EMAILOPTOUT] => 0 [OVERRIDEAUTOCLOSE] => 0 [LANGUAGE] => [LASTLOGIN] => Date: 07/10/2014 17:43 IP Address: xx.xx.xx.xx.xx Host: xx.xx.xx.xx.xx.xx.xx [CUSTOMFIELDS1] => Other [CUSTOMFIELDS] => Array ( [ID] => 1 [VALUE] => Other ) [CURRENCY_CODE] => USD ) [STATS] => Array ( [NUMDUEINVOICES] => 0 [DUEINVOICESBALANCE] => $0.00 USD [INCOME] => $0.00 USD [INCREDIT] => [CREDITBALANCE] => $0.00 USD [NUMOVERDUEINVOICES] => 0 [OVERDUEINVOICESBALANCE] => $0.00 USD [NUMPAIDINVOICES] => 0 [PAIDINVOICESAMOUNT] => $0.00 USD [NUMUNPAIDINVOICES] => 0 [UNPAIDINVOICESAMOUNT] => $0.00 USD [NUMCANCELLEDINVOICES] => 0 [CANCELLEDINVOICESAMOUNT] => $0.00 USD [NUMREFUNDEDINVOICES] => 0 [REFUNDEDINVOICESAMOUNT] => $0.00 USD [NUMCOLLECTIONSINVOICES] => 0 [COLLECTIONSINVOICESAMOUNT] => $0.00 USD [PRODUCTSNUMACTIVEHOSTING] => 0 [PRODUCTSNUMHOSTING] => 0 [PRODUCTSNUMACTIVERESELLER] => 0 [PRODUCTSNUMRESELLER] => 0 [PRODUCTSNUMACTIVESERVERS] => 0 [PRODUCTSNUMSERVERS] => 0 [PRODUCTSNUMACTIVEOTHER] => 0 [PRODUCTSNUMOTHER] => 0 [PRODUCTSNUMACTIVE] => 0 [PRODUCTSNUMTOTAL] => 0 [NUMACTIVEDOMAINS] => 0 [NUMDOMAINS] => 0 [NUMACCEPTEDQUOTES] => 0 [NUMQUOTES] => 0 [NUMTICKETS] => 0 [NUMACTIVETICKETS] => 0 [NUMAFFILIATESIGNUPS] => 0 ) ) ) How would I get that information into a variable I tried $params[1]; and that didn't work I tried to remove the return($params); and use it in CheckLogin.php and did echo $params; but it didn't work Any help appreciated!!!!! Quote Link to comment Share on other sites More sharing options...
TOA Posted July 11, 2014 Share Posted July 11, 2014 I believe what you want is CURLOPT_RETURNTRANSFER Quote Link to comment Share on other sites More sharing options...
Solution Barand Posted July 11, 2014 Solution Share Posted July 11, 2014 It looks as though it is already in the variable $arr. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.