I tried to generate hash MD5
for online payment processing and i'm getting hash invalid .
I found out that the MD5
function generates different results but I do not know why.
This is my part of code:
$tmp="330012345211.0024-01-2014:13:07:47:357newsecret";
$ab= md5($tmp);
$terminalid=33001;
$orderid=23452;
$amount=11.00;
$datetime=0024-01-2014:13:07:47:357;
$secret=newsecret;
$tmp1="$terminalid"."$orderid"."$amount"."$datetime"."$secret";
$aa=md5($tmp1);
Why is the result from $aa
different than $ab
?
$secret=newsecret;
In $ab
, newsecret
is a string.
In $aa
, newsecret
is being used as a constant because it's not enclosed in quotes. I presume you have not defined this as a constant, so add quotes.
$secret='newsecret';
Actually, none of your strings are enclosed in quotes.
$terminalid='33001';
$orderid='23452';
$amount='11.00';
$datetime='0024-01-2014:13:07:47:357';
$secret='newsecret';
(I'm enclosing the numbers in quotes, too, because IDs/numbers could begin with a 0
or end in .0
, which would likely be dropped when a number is implicitly typecast to a string.)
One other thing I noticed: you probably mistakenly copied the "00" at the start of $datetime
. Otherwise in $aa
you'll get "...11.000024..." instead of "...11.0024..." as in $ab
. Should probably be:
$datetime='24-01-2014:13:07:47:357';
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.