Generate a cryptographically secure token in PHP

$bytes = openssl_random_pseudo_bytes(32, $strong);

if ($strong !== true) {
    throw new RuntimeException('No strong entropy source available.');
}

$token = bin2hex($bytes);