I made a script to compare a downloaded copy of a file with the remote version via sha1 checksums to see if they match (to verify downloaded, check for changes, etc).
<?php
// $remote and $local are paths, one http and one local file
$local_sha1 = sha1_file($local, true);
$remote_sha1 = sha1_file($remote, true);
if($local_sha1 == $remote_sha1){
echo "Match\n";
} else {
echo "Mismatch\n";
}
// This says Mismatch every time.
?>
I downloaded the file again (via browser) and overwrote the local copy. Still mismatch.
For further testing:
<?php
$local_string = @file_get_contents($local);
$remote_string = @file_get_contents($remote);
strlen($local_string) == strlen($remote_string); // always true
$local_string == $remote_string; // always false
substr($local_string, $x, $l) == substr($remote_string, $x, $l);
// always true for any values of $x & $l, including negative values for $x
?>
I don't get it. Do you see something I'm missing? What other factor could affect the results?