Example 1 — Compare Two Tokens
A match returns true.
<?php
$saved = 'abc123token';
echo hash_equals($saved, 'abc123token') ? "Tokens match" : "Tokens differ", PHP_EOL;
echo hash_equals($saved, 'abc123tokeN') ? "Tokens match" : "Tokens differ", PHP_EOL; How It Works
- Keep the trusted token first. It comes from your server.
- Pass the user token second. It comes from the request.
- Get true for equal strings. The first call matches.
- Get false for any difference. Even one letter counts.

