Fingerprint the data. Save crc32($payload) with the record.
Recompute on read. Compare with ===.
Detect edits. Adding ! changes the CRC → mismatch.
Know the limit. Good for accidents; not proof against a clever attacker.
Frequently Asked Questions
crc32() calculates a 32-bit CRC (Cyclic Redundancy Check) checksum of a string and returns it as an integer. It is commonly used for quick data integrity checks, not for cryptographic security.
int crc32(string $string). Pass the data to checksum and receive a 32-bit integer. On 64-bit PHP the result is always a positive integer; on 32-bit systems it may appear negative.
PHP integers are signed. On 32-bit platforms, CRC values above 2^31-1 display as negative numbers even though the underlying checksum is valid. Use sprintf('%u', $crc) for the unsigned decimal string, or dechex($crc) for hexadecimal.
No. CRC32 is designed for error detection, not cryptography. It is fast but vulnerable to collisions and intentional manipulation. Use hash('sha256', $data) or password_hash() for security.
Both compute the same CRC32 polynomial. crc32() returns an integer; hash('crc32b', $data) returns an 8-character lowercase hex string equivalent to str_pad(dechex(crc32($data)), 8, '0', STR_PAD_LEFT).