Beispiel #1
0
 function random_message_id($length = 6)
 {
     // start with a blank string..
     // define possible characters
     //"0" is not an allowed digit, as a leading "0" could be misleading
     //total address space is approx 730M (30**6)
     //initially using only a subset of the address space (~120M) to allow for better database management
     $possible = "123456789bcdfghjklmnpqrstvwxyz";
     //$possible0 = "12345";//table "message"
     $possible0 = "a";
     //table "amessage"; allow "a" as a prefix, but not in the remaining 5 characters
     // set up a counter
     $i = 0;
     $j = 0;
     // add random characters to $password until $length is reached
     while ($j < 100) {
         $rand_message_id = "";
         while ($i < $length) {
             // pick a random character from the possible ones
             if ($i == 0) {
                 $char = substr($possible0, mt_rand(0, strlen($possible0) - 1), 1);
             } else {
                 $char = substr($possible, mt_rand(0, strlen($possible) - 1), 1);
             }
             $rand_message_id .= $char;
             $i++;
         }
         $model = new TwextraModel();
         $result = $model->urlHit($rand_message_id);
         if ($result == 'miss') {
             break;
         }
         $j++;
         $i = 0;
     }
     // done!
     return $rand_message_id;
 }