开发者

different sha1 checksum on different php versions?

I run this script:

define('SECRET', "vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5");
echo sha1(SECRET . 'zcb开发者_Python百科keyky' . 'aaa@bbb.com') . "\n";

Locally with PHP 5.3.2 (cli) it gives me: 3baa47e50394cd2dce236dcbf2f409fdb9010f2a

On a remote machine with PHP 5.1.6 (cli) it gives: d1bcf4ea83e50593d3df19a8455a5f5cd32d63ef

Why does the same calculation differ?


I'd say the problem is here:

define('SECRET', "vJs;ly-W\XDkD_2'-M7S2/ZRRBobxt5");
//                        ^^-- escape character

PHP manual says:

\x[0-9A-Fa-f]{1,2} the sequence of characters matching the regular expression is a character in hexadecimal notation

Between PHP 5.2 and 5.3, apparently this was modified to also match \X[0-9A-Fa-f]{1,2} (note the capital X at the beginning). When running in PHP 5.3, you have (unknowingly?) a Carriage Return in your string.

Either a) replace the backslash with another character, or b) use single quotes when defining SECRET, and both versions will return the same hash (tried on 5.2.1 and 5.3.2).


Only thing I can think of is the encoding of the files/strings on each server?

My result is 3baa47e50394cd2dce236dcbf2f409fdb9010f2a (Locally)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜