Search code snippets, questions, articles...

PHP program to generate a token that is cryptographically secured

You can use PHP openssl_random_pseudo_bytes() or random_bytes() methods to generate random bytes of a fixed number and then convert them to readable format using the bin2hex() method.
    $token = bin2hex(openssl_random_pseudo_bytes(20));
    echo "$token";

    // If you are using PHP 7 - You can also use
    $token = bin2hex(random_bytes(20));
    echo $token;

The code will generate a new random token each time you run the code.

Search Index Data (The code snippet can also be found with below search text)

generate secure token PHP
Was this helpful?
Programming Feeds
Learn something new everyday on Devsheet