phpmd5-file

PHP md5_file not the same on different machine


I have two simple PHP scripts: testHash.php and me.php. The testHash.php is simply doing a md5_file function to the me.php and printing out the result

testHash.php contains:

<?php 
 $test = md5_file(__DIR__."/me.php"); 
 echo $test;
 echo phpinfo();
?>

and me.php contains:

<?php
echo "Hello World";
?>

I have uploaded both script to two different Webserver using an FTP Tool (FileZilla) without of course touching the files. One is a local virtual machine and the other is a public Webserver.The output of the $test variable was different from the other. Both webserver operates on LAMP framework

  1. Local VM Webserver = 7633bbfa20ed2d29a55338913048eff0
  2. Public Webserver = 3a65329165abe28a485bed663da5e298

Why are they different from each other? Are there external factors (framework, PHP Versions, PHP configuration files) which affects the computation of the hash. Thank You.


Solution

  • The md5's are different if the files are.

    If you're transfering your file in ascii-mode, something in them could change, like the line endings changing from CRLF to LF.