PHP : Generate random unique string

AcceuilCategory: PHPPHP : Generate random unique string
Kanzari Haithem Staff asked 2 months ago

This is the function used actually to generate a random unique string :


public function rwGetRandom($length){
 
 $key = '';
 $keys = array_merge(range(0, 9), range('a', 'z'), range('A', 'Z'));
 for ($i = 0; $i < $length; $i++) {
 $key .= $keys[array_rand($keys)];
 }

 $d=date ("d");
 $m=date ("m");
 $y=date ("Y");
 $t=time();
 $dmt=$d+$m+$y+$t; 
 $ran= rand(0,10000000);
 $dmtran= $dmt+$ran;
 $un= uniqid();
 $dmtun = $dmt.$un;
 $mdun = sha1($dmtran.$key.$un.$this->session->userdata('id'));
 
 return $mdun;
 
}

This function should be reviewed and mayebe updated with new one.