A few days ago wrote a table program, using the hash algorithm is CRC32. The function of the table is as follows:
Copy Code code as follows:
function _gethash ($username)
{
$hash = CRC32 ($username)% 512;
return $hash;
}
function _gettable ($username)
{
$hash = Self::_gethash ($username);
Return ' User_ '. $hash;
}
First, the data is generated on the local 32-bit window machine and inserted into the corresponding table. But then the program and data uploaded to the server (64 for Linux), found no data. After the investigation found that the original server CRC32 results and local differences. Check the PHP manual to know that the interface between the original and the Machine CRC32.
Description of the PHP manual:
Copy Code code as follows:
Because PHP ' s integer type is signed many CRC32 checksums'll result in negative integers on 32bit platforms. On 64bit installations all CRC32 () results'll be positive integers though.
The result returned by CRC32 will overflow on the 32-bit machine, so the result may be negative. The 64-bit machine will not overflow, so always positive.
The CRC algorithm is calculated by the bit of the word length digit.
The CRC32 function is calculated according to the two constants referenced in PHP Php_int_size,php_int_max
The definitions of these two constants are:
The length of the integer is related to the platform, although usually the maximum value is approximately 2 billion (32-bit signed). PHP does not support unsigned integers. The length of the integer value can be represented by a constant php_int_size, which can be represented by a constant php_int_max since the PHP 4.4.0 and PHP 5.0.5.
32-bit php_int_size:4,php_int_max:2147483647 in output
64-bit php_int_size:8,php_int_max:9223372036854775807 in output