Search code examples
phphashhashcode

Given the hash-generating script in php, how do I post the resultant hash?


The resultant hashcode was requested by a payments processor. I already had most of the information they requested posting correctly, now they require this hashcode. I don't understand the format of the POST request, nor which variable the snippet of code is creating. If I run it in a form, what is the value of the hashcode?

For example <input type="hidden" name="hash" value="<?php ($WhatGoesHere); ?>" />

<?php
$storename = "TEST_STORE"; 
$sharedSecret = "777777777777777700000000000000005555555555555555"; 
date_default_timezone_set("America/Chicago");
$timezone = "CDT";
$dateTime = date("Y:m:d-H:i:s");
function getDateTime() {
global $dateTime;
return $dateTime;
}
function getTimezone() {
global $timezone;
return $timezone;
}
function getStorename() {
global $storename;
return $storename;
}
function createHash($chargetotal) {
global $storename, $sharedSecret;
$str = $storename . getDateTime() . $chargetotal . $sharedSecret;
for ($i = 0; $i < strlen($str); $i++){
$hex_str.=dechex(ord($str[$i]));
}
return hash('sha256', $hex_str);
}  
?>

Thank you in advance.


Solution

  • I see 4 different options:

    • Store in SESSION
    • Store in a hidden textbox and submit via POST
    • Store in a cookie and read out the value
    • Store in a database permanently

    I recommend not to use global