mardi 31 janvier 2017

Create a unique random ID

Since couple of days, i have a problem with my function who generate a random id.

Here is the function :

public static function generatePin($max)
{
        $key = "";
        $possibilities = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        $possibilities .= "abcdefghijklmnopqrstuvwxyz";
        $possibilities .= "0123456789";
        $i = 0;
        while ($i <= $max) {
            $detail = Tools::substr($possibilities, mt_rand(0, Tools::strlen($possibilities)-1), 1);
            $key .= $detail;
            $i++;
        }
        return $key;

In my file, when i want to use this function, i used to do that (works fine since many months) :

    $this->my_secure_pin = Tools::encrypt(Class::generatePin(7));

Now, my variable "secure_pin" can't change.. I always have the same ID and it doesn't want to change as it used to do.. My random ID become a same ID for every request.. Grrrr

No changes, No updates, nothing.. Any idea ? :'(

Many thanks for your help !




Aucun commentaire:

Enregistrer un commentaire