Rob
Rob

Reputation: 8101

Why is the same input returning two different MD5 hashes?

Alright, I have two files. They are the EXACT SAME.

The first file is: http://iadsonline.com/servconfig.php

And the second file is: http://xzerox.info/servconfig.php

However, when I use md5_file() to get their MD5, They return two different MD5's.

The first returns cc7819055cde3194bb3b136bad5cf58d, which is incorrect, and the second returns 96a0cec80eb773687ca28840ecc67ca1, which is correct.

The file is simply an  

To verify, I've used this code:

$contents = file_get_contents($URL);
echo htmlentities($contents);

And they both return  

So why is it hashing them differently?

Upvotes: 5

Views: 6127

Answers (4)

Feras Jobeir
Feras Jobeir

Reputation: 36

this also happened with me. I set the same encoding (utf-8 without BOM) to all files that store and retrieve hashed strings :) now md5() gives the same results :)

Upvotes: 0

alex
alex

Reputation: 490647

Could you have whitespace in either of those files? Open them up in a text editor and show all characters.

Alternatively, run something like this

echo str_replace(array("\n", "\t", "\r"), '[I AM HIDING!]', file_get_contents($URL));

If you see [I AM HIDING!], you will know what to do :)

Upvotes: 0

Alex Martelli
Alex Martelli

Reputation: 882751

Trying with curl, I see the first one is   without a newline after it, the second one is   with a newline after it. So of course they'll hash differently. And indeed, even at the command line (bash prompt):

$ md5 sc.dat 
MD5 (sc.dat) = cc7819055cde3194bb3b136bad5cf58d
$ md5 zz.dat
MD5 (zz.dat) = 96a0cec80eb773687ca28840ecc67ca1

Upvotes: 3

Matthew Flaschen
Matthew Flaschen

Reputation: 285077

The second one ends in a newline, the first does not.

Upvotes: 8

Related Questions