View Full Version : problem sending XML query via cURL

09-22-2005, 03:14 PM
I am working on this system where a user logs in and can enter data into a HTML form and then recieve a credit report, bankruptcy report, etc..

I created a system where the data is passed through the $_POST function into a hidden form field where posted data would go in between XML tags. like <name-first>$_Post['$fname'].......</name-first>... etc...
This worked in theory, but the data is posted to another server that contains these reports and the result returned was in XML format..

On to the problem
I have resorted to using the cURL function based on a tutorial I found (http://www.phpfreaks.com/tutorials/49/1.php)

but in the tutorial, the data was in XML. I cannot get the code to work in sending a XML query to the server and having the server return the report (in any format) without going to the actual XML page.

here is my code:

include 'prop_form.php';

case "post":
$postfields = array();
$postfields[] = array("<userid>USER</userid>");
$postfields[] = array("<password>PASS </password>");
$postfields[] = array("<name-first>", $_POST['$fname'],"</name-first>");
$postfields[] = array("<name-last>", $_POST['$lname'],"</name-last>");
$postfields[] = array("<dob>", $_POST['$year']);
$postfields[] = array($_POST['$month']);
$postfields[] = array($_POST['$day'],"</dob>");

foreach($postfields as $subarray) {
list($foo, $bar) = $subarray;
$bar = urlencode($bar);
$postedfields[] = "$foo=$bar";

$urlstring = join("\n", $postedfields);
$urlstring = ereg_replace("\n", "&", $urlstring);
// echo $urlstring;

$ch = curl_init("https://xml.securint.com/services/test");
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $urlstring);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
curl_setopt($ch, CURLOPT_REFERER, "http://www.hmscredit.com/");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$data = curl_exec($ch);

$response_start = strPos($data, "Server Response:");
$response_end = strPos($data, "\n");
$temp_code = substr($data, $response_start, ($response_end - $response_start));
$temp_code = str_replace("Server Response:", "", $temp_code);
$temp_code = strip_tags($temp_code);
$transaction_code = trim($temp_code);

case "Transaction Success!":
//redirect person to thank you page
echo "Success!!!!!!!!";
echo $data;

echo '<font color="red">Transaction Error: '.$transaction_code.'</font>';
include 'form.html';


I also considering scratching the array and making the query a variable and using the $_Post[' thedata'] method but no luck with that either.

any ideas?