Why does the same input return two different MD5 hashes?

Ok, I have two files. They are EXACTLY SUCH.

First file: http://iadsonline.com/servconfig.php

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

However, when I use md5_file () to get MD5, they return two different MD5.

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

The file is simply  

To check, I used this code:

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

And they both return  

So why does he hash them differently?

+4
php md5
source share
4 answers

The second ends with a newline, the first does not.

+7
source share

Trying with curl , I see that the first one is   without , after it - a new line, the second -   with a newline after it, so of course they will hash in different ways. And indeed, even on the command line (bash prompt):

 $ md5 sc.dat MD5 (sc.dat) = cc7819055cde3194bb3b136bad5cf58d $ md5 zz.dat MD5 (zz.dat) = 96a0cec80eb773687ca28840ecc67ca1 
+3
source share

Do you have spaces in any of these files? Open them in a text editor and show all the characters.

Also, run something like this

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

If you see [I HIDE!], You will know what to do :)

0
source share

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

0
source share

All Articles