function randstr($length) { $hash = &#39;&#39;; $chars = &#39;abcdefghijklmnopqrstuvwxyz0123456789abcdefghijklmnopqrstuvwxyz&#39;; $max = strlen($chars) - 1; mt_srand((double)microtime() * 1000000); for($i = 0; $i < $length; $i++) { $hash .= $chars[mt_rand(0, $max)]; } return $hash; }