Marcus Barnet
asked on
[PHP] Hash a XML file/string
Hi to all, I'm not a PHP expert and so I hope you can help me with my problem! :)
I'm trying to implement a payment method on my website and I'm having troubles with the transaction code.
I have a string where I loaded some XML content with tags and values.
I need to hash the whole XML content using MD5 algorithm, (Encoding Windows-1252), and then replace the content of the value of the first XML tag with the hashing value and saving it in a new string deleting all empty spaces.
I try to explain you better what I would like to do:
I have this string:
I need to hash (using the MD5 algorithm) the whole string and replace the value of "$secretWord" in <Transaction> tag with the hashing result, by updating the string content. For example, if the hashing result is: FFD93F16256349265FBAEBBAF2 68DD0E, then the new content for transactionXmlString would be:
Can you help me to solve this problem, please?
I tried to directly use the md5() function in this way:
I'm trying to implement a payment method on my website and I'm having troubles with the transaction code.
I have a string where I loaded some XML content with tags and values.
I need to hash the whole XML content using MD5 algorithm, (Encoding Windows-1252), and then replace the content of the value of the first XML tag with the hashing value and saving it in a new string deleting all empty spaces.
I try to explain you better what I would like to do:
I have this string:
$transactionXmlString = "<Transaction hash=\"" .$secretWord. "\">";
$transactionXmlString .= "<RedirectionURL>" . $redirectionUrl . "</RedirectionURL>";
$transactionXmlString .= "<status_url>" . $statusUrl . "</status_url>";
$transactionXmlString .= "<FailedRedirectionURL>" . $failedRedirectionUrl . "</FailedRedirectionURL>";
$transactionXmlString .= "<ProfileID>" . $profileID . "</ProfileID>";
$transactionXmlString .= "<ActionType>" . $actionType . "</ActionType>";
$transactionXmlString .= "<Value>" . $value . "</Value>";
$transactionXmlString .= "<Curr>" . $currency . "</Curr>";
$transactionXmlString .= "<Email>" . $email . "</Email>";
$transactionXmlString .= "<Lang>" . $language . "</Lang>";
$transactionXmlString .= "<Enc />";
$transactionXmlString .= "<ORef>" . $orderReference . "</ORef>";
$transactionXmlString .= "<ClientAcc>" . $clientAccount . "</ClientAcc>";
$transactionXmlString .= "<MobileNo>" . $mobileNo . "</MobileNo>";
$transactionXmlString .= "<Address>" . $address . "</Address>";
$transactionXmlString .= "<Country>" . $country . "</Country>";
$transactionXmlString .= "<RegName>" . $regName . "</RegName>";
$transactionXmlString .= "<ListAllCards>" . $listAllCards . "</ListAllCards>";
$transactionXmlString .= "<NewCard1Try />";
$transactionXmlString .= "<CardRestrict />";
$transactionXmlString .= "<UDF1>" . $udf1 . "</UDF1>";
$transactionXmlString .= "<UDF2>" . $udf2 . "</UDF2>";
$transactionXmlString .= "<UDF3>" . $udf3. "</UDF3>";
$transactionXmlString .= "<PspID>" . $PspID . "</PspID>";
$transactionXmlString .= "<HideSSLLogo />";
$transactionXmlString .= "</Transaction>";
I need to hash (using the MD5 algorithm) the whole string and replace the value of "$secretWord" in <Transaction> tag with the hashing result, by updating the string content. For example, if the hashing result is: FFD93F16256349265FBAEBBAF2
$transactionXmlString = "<Transaction hash=" [b]FFD93F16256349265FBAEBBAF268DD0E[/b]">";
$transactionXmlString .= "<RedirectionURL>" . $redirectionUrl . "</RedirectionURL>";
$transactionXmlString .= "<status_url>" . $statusUrl . "</status_url>";
$transactionXmlString .= "<FailedRedirectionURL>" . $failedRedirectionUrl . "</FailedRedirectionURL>";
$transactionXmlString .= "<ProfileID>" . $profileID . "</ProfileID>";
$transactionXmlString .= "<ActionType>" . $actionType . "</ActionType>";
$transactionXmlString .= "<Value>" . $value . "</Value>";
$transactionXmlString .= "<Curr>" . $currency . "</Curr>";
$transactionXmlString .= "<Email>" . $email . "</Email>";
$transactionXmlString .= "<Lang>" . $language . "</Lang>";
$transactionXmlString .= "<Enc />";
$transactionXmlString .= "<ORef>" . $orderReference . "</ORef>";
$transactionXmlString .= "<ClientAcc>" . $clientAccount . "</ClientAcc>";
$transactionXmlString .= "<MobileNo>" . $mobileNo . "</MobileNo>";
$transactionXmlString .= "<Address>" . $address . "</Address>";
$transactionXmlString .= "<Country>" . $country . "</Country>";
$transactionXmlString .= "<RegName>" . $regName . "</RegName>";
$transactionXmlString .= "<ListAllCards>" . $listAllCards . "</ListAllCards>";
$transactionXmlString .= "<NewCard1Try />";
$transactionXmlString .= "<CardRestrict />";
$transactionXmlString .= "<UDF1>" . $udf1 . "</UDF1>";
$transactionXmlString .= "<UDF2>" . $udf2 . "</UDF2>";
$transactionXmlString .= "<UDF3>" . $udf3. "</UDF3>";
$transactionXmlString .= "<PspID>" . $PspID . "</PspID>";
$transactionXmlString .= "<HideSSLLogo />";
$transactionXmlString .= "</Transaction>";
Can you help me to solve this problem, please?
I tried to directly use the md5() function in this way:
$xml_hash = md5($transactionXmlString);
echo $xml_hash;
but it doesn't seem to work.
ASKER
Thank you, Ray, I will wait for it! :)
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
To get around that, create the XML document in multiple parts - one that contains the hash data, and another that contains the "live" data. I'll post an example for you in a moment.