PHP Function that Generates Random Characters

1
2
3
4
5
6
7
8
9
10
11
12
13
function cvf_ps_generate_random_code($length=10) {
 
   $string = '';
   // You can define your own characters here.
   $characters = "23456789ABCDEFHJKLMNPRTVWXYZabcdefghijklmnopqrstuvwxyz";
 
   for ($p = 0; $p < $length; $p++) {
       $string .= $characters[mt_rand(0, strlen($characters)-1)];
   }
 
   return $string;
 
}