Hi,

I want to send a XML file to my website where the XML is read and information passed to MySQL database. I know this is done but i don't know how to do it.

Something related to header etc?
Any idea?

Thanks

Recommended Answers

All 6 Replies

SimpleXML (Google it)
Its simple and it handles XML files :P

may be it can help you

http://www.experts-exchange.com/Database/MySQL/Q_22799583.html

[YOUR FORM SNIPPET HERE]



<?php


if ($_POST["server"] == "live")
	if ($_POST["payment_type"] == 15 || $_POST["payment_type"] == 17)
		$host = "www.cute.com";
	else
		$host = "www.cute.com";
else
	if ($_POST["payment_type"] == 15 || $_POST["payment_type"] == 17)
		$host = "www.cute.com";
	else
		//$host = "www.cute.com";
		//Or if using SSL:
		$host = "www.cute2.com";

$timestamp = getGMTtimestamp();

$vars = 
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>" .
"<SecurePayMessage>" .
	"<MessageInfo>" .
		"<messageID>8af793f9af34bea0cf40f5fb5c630c</messageID>" .
		"<messageTimestamp>" .urlencode($timestamp). "</messageTimestamp>" .
		"<timeoutValue>60</timeoutValue>" .
		"<apiVersion>xml-4.2</apiVersion>" .
	"</MessageInfo>" .
	"<MerchantInfo>" .
		"<merchantID>" .urlencode($_POST["merchant_id"]). "</merchantID>" .
		"<password>" .urlencode($_POST["transaction_password"]). "</password>" .
	"</MerchantInfo>" .
	"<RequestType>" .urlencode($_POST["request_type"]). "</RequestType>" .
	"<Payment>" .
		"<TxnList count=\"1\">" .
			"<Txn ID=\"1\">" .
				"<txnType>" .urlencode($_POST["payment_type"]). "</txnType>" .
				"<txnSource>23</txnSource>" .
				"<amount>" .str_replace(".", "", urlencode($_POST["payment_amount"])). "</amount>" .
				"<purchaseOrderNo>" .urlencode($_POST["payment_reference"]). "</purchaseOrderNo>" .
				"<currency>" .urlencode($_POST["currency"]). "</currency>" .
				"<preauthID>" .urlencode($_POST["preauthid"]). "</preauthID>" .
				"<txnID>" .urlencode($_POST["txnid"]). "</txnID>" .
				"<CreditCardInfo>" .
					"<cardNumber>" .urlencode($_POST["card_number"]). "</cardNumber>" .
					"<cvv>" .urlencode($_POST["card_cvv"]). "</cvv>" .
					"<expiryDate>" .urlencode($_POST["card_expiry_month"]). "/" .urlencode($_POST["card_expiry_year"]). "</expiryDate>" .
				"</CreditCardInfo>" .
				"<DirectEntryInfo>" .
					"<bsbNumber>" .urlencode($_POST["bsb_number"]). "</bsbNumber>" .
					"<accountNumber>" .urlencode($_POST["account_number"]). "</accountNumber>" .
					"<accountName>" .urlencode($_POST["account_name"]). "</accountName>" .
				"</DirectEntryInfo>" .
			"</Txn>" .
		"</TxnList>" .
	"</Payment>" .
"</SecurePayMessage>";

$response = openSocket($host, $vars);

$xmlres = array();
$xmlres = makeXMLTree ($response);

/*
// Display Array contents.
echo "<pre>";
print_r($xmlres);
echo "</pre>";
*/

echo "<h1>The Server has responded.</h1>";
echo "<p><hr /></p><h1>Recover the Response:</h1>";

$messageID = trim($xmlres[SecurePayMessage][MessageInfo][messageID]);
echo "<p>messageID = ".$messageID."</p>";

$messageTimestamp = trim($xmlres[SecurePayMessage][MessageInfo][messageTimestamp]);
echo "<p>messageTimestamp = ".$messageTimestamp."</p>";

$apiVersion = trim($xmlres[SecurePayMessage][MessageInfo][apiVersion]);
echo "<p>apiVersion = ".$apiVersion."</p>";

$RequestType = trim($xmlres[SecurePayMessage][RequestType]);
echo "<p>RequestType = ".$RequestType."</p>";

$merchantID = trim($xmlres[SecurePayMessage][MerchantInfo][merchantID]);
echo "<p>merchantID = ".$merchantID."</p>";

$statusCode = trim($xmlres[SecurePayMessage][Status][statusCode]);
echo "<p>statusCode = ".$statusCode."</p>";

$statusDescription = trim($xmlres[SecurePayMessage][Status][statusDescription]);
echo "<p>statusDescription = ".$statusDescription."</p>";

$txnType = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][txnType]);
echo "<p>txnType = ".$txnType."</p>";

$txnSource = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][txnSource]);
echo "<p>txnSource = ".$txnSource."</p>";

$amount = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][amount]);
echo "<p>amount = ".$amount."</p>";

$currency = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][currency]);
echo "<p>currency = ".$currency."</p>";

$purchaseOrderNo = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][purchaseOrderNo]);
echo "<p>purchaseOrderNo = ".$purchaseOrderNo."</p>";

$approved = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][approved]);
echo "<p>approved = ".$approved."</p>";

$responseCode = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][responseCode]);
echo "<p>responseCode = ".$responseCode."</p>";

$responseText = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][responseText]);
echo "<p>responseText = ".$responseText."</p>";

$settlementDate = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][settlementDate]);
echo "<p>settlementDate = ".$settlementDate."</p>";

$txnID = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][txnID]);
echo "<p>txnID = ".$txnID."</p>";

$preauthID = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][preauthID]);
echo "<p>preauthID = ".$preauthID."</p>";

$pan = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][CreditCardInfo][pan]);
echo "<p>pan = ".$pan."</p>";

$expiryDate = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][CreditCardInfo][expiryDate]);
echo "<p>expiryDate = ".$expiryDate."</p>";

$cardType = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][CreditCardInfo][cardType]);
echo "<p>cardType = ".$cardType."</p>";

$cardDescription = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][CreditCardInfo][cardDescription]);
echo "<p>cardDescription = ".$cardDescription."</p>";

$bsbNumber = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][DirectEntryInfo][bsbNumber]);
echo "<p>bsbNumber = ".$bsbNumber."</p>";

$accountNumber = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][DirectEntryInfo][accountNumber]);
echo "<p>accountNumber = ".$accountNumber."</p>";

$accountName = trim($xmlres[SecurePayMessage][Payment][TxnList][Txn][DirectEntryInfo][accountName]);
echo "<p>accountName = ".$accountName."</p>";


echo "<p><hr /><a href=\"SecureXML_PHP_Basic_example.php\">Return to Payment Page</a></p>";


		// expression
		break;
	default:
		// expression
		break;
}

?>


<?
function getGMTtimeStamp()
{
	$stamp = date("YmdGis")."000+1000";
	return $stamp;
}

/**************************/
/* Secure Socket Function */
/**************************/
function openSocket($host,$query){
        // Break the URL into usable parts
        $path = explode('/',$host);
        $host = $path[0];
        unset($path[0]);
        $path = '/'.(implode('/',$path));



        // Prepare the post query
        $post  = "POST $path HTTP/1.1\r\n";
        $post .= "Host: $host\r\n";
        $post .= "Content-type: application/x-www-form-urlencoded\r\n";
        $post .= "Content-type: text/xml\r\n";
        $post .= "Content-length: ".strlen($query)."\r\n";
        $post .= "Connection: close\r\n\r\n$query";

		//echo "<p>post = </p>";
		//echo $post;

        /***********************************************/
        /* Open the secure socket and post the message */
        /***********************************************/
       $h = fsockopen("ssl://".$host, 443, $errno, $errstr);

        if ($errstr)
                print "$errstr ($errno)<br/>\n";
        fwrite($h,$post);

        /*******************************************/
        /* Retrieve the HTML headers (and discard) */
        /*******************************************/

//echo "<pre>";

        $headers = "";
        while ($str = trim(fgets($h, 4096))) {
//echo "Headers1: ".$str."\n";
                $headers .= "$str\n";
        }

        $headers2 = "";
        while ($str = trim(fgets($h, 4096))) {
//echo "Headers2: ".$str."\n";
                $headers2 .= "$str\n";
        }

//echo "</pre>";


        /**********************************************************/
        /* Retrieve the response */
        /**********************************************************/

        $body = "";
        while (!feof($h)) {
                $body .= fgets($h, 4096);
        }

        // Close the socket
        fclose($h);

        // Return the body of the response

        return $body;
}

	function makeXMLTree ($data) {
	   $output = array();
	   
	   $parser = xml_parser_create();

	   xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
	   xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
	   xml_parse_into_struct($parser, $data, $values, $tags);
	   xml_parser_free($parser);
	   
	   $hash_stack = array();
	   
	   foreach ($values as $key => $val)
	   {
		   switch ($val['type'])
		   {
			   case 'open':
				   array_push($hash_stack, $val['tag']);
				   break;
		   
			   case 'close':
				   array_pop($hash_stack);
				   break;
		   
			   case 'complete':
				   array_push($hash_stack, $val['tag']);
				   eval("\$output['" . implode($hash_stack, "']['") . "'] = \"{$val['value']}\";");
				   array_pop($hash_stack);
				   break;
		   }
	   }

	   return $output;
   }
?>

try to modify that code...according to your need....

I'll try it as soon as possible. Thanks for now.

Hi rm_daniweb,

I have tried the example you have pasted but it doesn't work because i dont have SSL.

i gave you the code my friend not to follow exactly. Modified the code according to your need. That code if for payment gateway...you are not doing a payment gateway so you don't have the SSL.

Remove the SSL code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.