php random alphanumeric

Posted by w3diy - 5 months ago

How to generate a random, unique, alphanumeric string in PHP?

Generate Random Alphanumeric String

This is a simple function that allows you to generate random strings containing Letters and Numbers (alphanumeric) using core PHP Script .

function live_random_code($totsal)
{
    return substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, $totsal);
}

echo live_random_code(8);

Here's the output samples

hkhkjuyu
143jfkde
d1m92z6i
8gf6cd95