mercredi 9 juin 2021

PHP How to render Unique Key?

I would like to render such a key or similar, but I don't want the "-" sign to appear at the beginning. My current code means that this character can also be generated at the beginning, and I would like it never to be generated at the beginning and at the end, but only in the middle after the X character from the end and the beginning, where X is the number of characters from the side

6LdBaA6aBxOAsj0AoTJ8rC-NbzpzAPgVaAz1bnAE

My Code

// Generowanie Unique Key
if(!function_exists('genetateUniqueKey')){
    function genetateUniqueKey($length = 40){
        $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0987654321-'.time();
        $charactersLength = strlen($characters);
        $randomString = '';
        for($i = $length; $i > 0; $i--){
            $randomString .= $characters[rand(0, $charactersLength - 1)];
        }
        return $randomString;
    }
}

Thank you in advance for your help :)




Aucun commentaire:

Enregistrer un commentaire