mardi 2 juin 2015

Random string generator PHP

I'm trying to create a random string with numbers and letters and I found this function and thought it would be good, but I don't know if it is the correct way to create a true random string or if there is an easier way to do this? Below is what I have:

function randomGen() {
    $chars = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $length = strlen($chars);
    $random;

    for ($i = 0; $i < 8; $i++) {
        $random = $chars[rand(0, $length - 1)];
    }

    return $random;
}




Aucun commentaire:

Enregistrer un commentaire