tags:

views:

128

answers:

3

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?

+7  A: 

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

Matthew Flaschen
+3  A: 

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
Alex Martelli
You can also run `echo " " | md5sum` versus `echo -n " " | md5sum`
Michael Mrozek
A: 

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 :)

alex