Search code snippets, questions, articles... Chrome Extension

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;
Best JSON Validator, JSON Tree Viewer, JSON Beautifier at same place. Check how cool is the tool

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?
Join Devsheet Ask a Question