public static function make_newkey() { $status = 0; $key = ''; while ($status == 0) { $str = ''; for ($i = 1; $i <= 15; $i++) { $n = rand(1, 3); switch ($n) { case 1: $str = $str . chr(rand(65, 90)); #大寫英文 break; case 2: $str = $str . chr(rand(97, 122)); #小寫英文 break; case 3: $str = $str . chr(rand(48, 57)); #數字 break; } } $keydata = ''; $keydata = dbconn::get_usrkey($str); if (empty($keydata)) { $status = 1; } } return $str; }