Jump to content

Help using CURL and XML


dfowler

Recommended Posts

Hey guys, I'm trying to use curl to connect to a screening company entitled DataX.  However, I keep getting the following error:

Parse error: syntax error, unexpected T_DNUMBER in C:\www\webroot\location\company\datax_test.php on line 2

 

Here is the code:

<?php
$datax_info = "<?XML VERSION="1.0" ENCODING="ISO-8859-1"?>";
$datax_info .= "<DATAXINQUIRY>";
$datax_info .= "<AUTHENTICATION>";
$datax_info .= "<LICENSEKEY>".$key."</LICENSEKEY>";
$datax_info .= "<PASSWORD>".$password."</PASSWORD>";
$datax_info .= "</AUTHENTICATION>";
$datax_info .= "<QUERY>";
$datax_info .= "<TRACKID>".$track_id."</TRACKID>";
$datax_info .= "<TYPE>".$type."</TYPE>";
$datax_info .= "<DATA>";
$datax_info .= "<NAMEFIRST>".$name_first."</NAMEFIRST>";
$datax_info .= "<NAMELAST>".$name_last."</NAMELAST>";
$datax_info .= "<STREET1>".$address_1."</STREET1>";
$datax_info .= "<STREET2>".$address_2."</STREET2>";
$datax_info .= "<CITY>".$city."</CITY>";
$datax_info .= "<STATE>".$state."</STATE>";
$datax_info .= "<ZIP>".$zipcode."</ZIP>";
$datax_info .= "<PHONEHOME>".$phone_home."</PHONEHOME>";
$datax_info .= "<PHONECELL>".$phone_cell."</PHONECELL>";
$datax_info .= "<PHONEWORK>".$phone_work."</PHONEWORK>";
$datax_info .= "<PHONEEXT>".$emp_phone_ext."</PHONEEXT>";
$datax_info .= "<EMAIL>".$email_address."</EMAIL>";
$datax_info .= "<DOBYEAR>".$birth_year."</DOBYEAR>";
$datax_info .= "<DOBMONTH>".$birth_month."</DOBMONTH>";
$datax_info .= "<DOBDAY>".$birth_day."</DOBDAY>";
$datax_info .= "<SSN>".$dp_ssn."</SSN>";
$datax_info .= "<DRIVERLICENSENUMBER>".$DLNumber."</DRIVERLICENSENUMBER>";
$datax_info .= "<DRIVERLICENSESTATE>".$DLState."</DRIVERLICENSESTATE>";
$datax_info .= "<WORKNAME>".$employer."</WORKNAME>";
$datax_info .= "<BANKNAME>".$bank_name."</BANKNAME>";
$datax_info .= "<BANKACCTNUMBER>".$account_number."</BANKACCOUNT>";
$datax_info .= "<BANKABA>".$account_routing."</BANKABA>";
$datax_info .= "</DATA>";
$datax_info .= "</QUERY>";
$datax_info .= "</DATAXINQUIRY>";

$url = "https://rc.verihub.com/datax/";
$page = "/datax/";

$headers = array(
"POST ".$page." HTTP/1.0",
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: \"run\"",
);

$datax_ch = curl_init();
curl_setopt($datax_ch, CURLOPT_URL,$url);
curl_setopt($datax_ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($datax_ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
curl_setopt($datax_ch, CURLOPT_POST, 1);
curl_setopt($datax_ch, CURLOPT_POSTFIELDS, $datax_info);
curl_setopt($datax_ch, CURLOPT_RETURNTRANSFER, 1);

$datax_result = curl_exec($datax_ch);

if (curl_errno($datax_ch)) {
print curl_error($datax_ch);
}
curl_close($datax_ch);

$datax_xml = new SimpleXMLElement($datax_result);
?>

 

Anybody know what I am doing wrong?  Or have a better way to do this?

Link to comment
https://forums.phpfreaks.com/topic/99553-help-using-curl-and-xml/
Share on other sites

Ok, I feel dumb, I just noticed the quotes on the very first line.  Now I'm getting this:

 

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\www\webroot\location\company\datax_test.php:65 Stack trace: #0 C:\www\webroot\location\company\datax_test.php(65): SimpleXMLElement->__construct('') #1 {main} thrown in C:\www\webroot\location\company\datax_test.php on line 65

You can add in the line:

 

curl_setopt($datax_ch, CURLOPT_SSL_VERIFYPEER, FALS;

 

Which should fix the issue. Of course, this does give some potential security issues given that you're no longer interested in the SSL certificate. But if you're not sending any sensitive information, I dont suppose it will be an issue.

 

Otherwise, you may have luck manipulating some of the SSL related options listed here:

 

http://uk.php.net/curl_setopt

 

  • 2 weeks later...

Sorry it has taken me so long to respond.  As you can look at the XML I am going to be sending sensitive information.  So keeping the security is a must.  I cleaned up a lot of the unnecessary code and here is what I have currently:

 

<?php
$datax_info = '<?XML VERSION="1.0" ENCODING="ISO-8859-1"?><DATAXINQUIRY><AUTHENTICATION><LICENSEKEY>15145f57be3d958276fe07b0557ef0a7</LICENSEKEY>';
$datax_info .= '<PASSWORD>afbbc5464fbf</PASSWORD></AUTHENTICATION><QUERY><TRACKID>ABC1234</TRACKID><TYPE>pdla-idve2cra</TYPE><DATA>';
$datax_info .= "<NAMEFIRST>".$name_first."</NAMEFIRST><NAMELAST>".$name_last."</NAMELAST><STREET1>".$address_1."</STREET1><STREET2>".$address_2."</STREET2>";
$datax_info .= "<CITY>".$city."</CITY><STATE>".$state."</STATE><ZIP>".$zipcode."</ZIP><PHONEHOME>".$phone_home."</PHONEHOME><PHONECELL>".$phone_cell."</PHONECELL>";
$datax_info .= "<PHONEWORK>".$phone_work."</PHONEWORK><PHONEEXT>".$emp_phone_ext."</PHONEEXT><EMAIL>".$email_address."</EMAIL><DOBYEAR>".$birth_year."</DOBYEAR>";
$datax_info .= "<DOBMONTH>".$birth_month."</DOBMONTH><DOBDAY>".$birth_day."</DOBDAY><SSN>".$dp_ssn."</SSN><DRIVERLICENSENUMBER>".$DLNumber."</DRIVERLICENSENUMBER>";
$datax_info .= "<DRIVERLICENSESTATE>".$DLState."</DRIVERLICENSESTATE><WORKNAME>".$employer."</WORKNAME><BANKNAME>".$bank_name."</BANKNAME><BANKACCTNUMBER>".$account_number."</BANKACCOUNT>";
$datax_info .= "<BANKABA>".$account_routing."</BANKABA></DATA></QUERY></DATAXINQUIRY>";

$datax_ch = curl_init();
curl_setopt($datax_ch, CURLOPT_URL, 'https://rc.verihub.com/datax/');
curl_setopt($datax_ch, CURLOPT_SSL_VERIFYPEER, TRUE);
curl_setopt($datax_ch, CURLOPT_POST, 1);
curl_setopt($datax_ch, CURLOPT_POSTFIELDS, $datax_info);
curl_setopt($datax_ch, CURLOPT_RETURNTRANSFER, 1);
$datax_result = curl_exec($datax_ch);

if (curl_errno($datax_ch)) {
print curl_error($datax_ch);
}

curl_close($datax_ch);

$datax_xml = new SimpleXMLElement($datax_result);
?>

 

The problem is still there with the cert though as I still get the following error:

SSL certificate problem, verify that the CA cert is OK. Details: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed

Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in C:\www\webroot\PLOA-Web\payday\datax_test.php:25 Stack trace: #0 C:\www\webroot\PLOA-Web\payday\datax_test.php(25): SimpleXMLElement->__construct('') #1 {main} thrown in C:\www\webroot\PLOA-Web\payday\datax_test.php on line 25

The data will still be sent over SSL, it's just that PHP can't verify the SSL certificate on the remote server. Is the remote server using a self-signed certificate?

 

At this point I'm not sure, I sent them an email asking if they are or not.  They aren't very knowledgeable when it comes to PHP so all my efforts to work with their team have come up empty.  They just keep asking me to verify my XML?!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.