PHP Tricks
September 10

How to generate random string in PHP?

The simplest way is using bin2hex function:

<?php
$str_len = 8;
$random_string = bin2hex(random_bytes($str_len));

echo $random_string;

PHP online sandbox