GroundZeroStudios Posted March 28, 2007 Share Posted March 28, 2007 All I need to know is how to come up with a random alphanumeric string 24 characters long. Such as Dj53dljgdg97dgfhgf879ngf. It doesn't need to contain upper-case letters. *Alphanumeric means containing letters and numbers Quote Link to comment Share on other sites More sharing options...
JBS103 Posted March 29, 2007 Share Posted March 29, 2007 This should work. No clue if it would be considered "good practice" or not. $var = substr(md5(mt_rand()), ; //or $var = substr(md5(time()), ; Quote Link to comment Share on other sites More sharing options...
Lytheum Posted March 29, 2007 Share Posted March 29, 2007 function get_rand_id($length) { if($length>0) { $rand_id=""; for($i=1; $i<=$length; $i++) { mt_srand((double)microtime() * 1000000); $num = mt_rand(1,36); $rand_id .= assign_rand_value($num); } } return $rand_id; } Usage: $id = get_rand_id(24); // Returns random 24 character string. Quote Link to comment Share on other sites More sharing options...
Barand Posted March 29, 2007 Share Posted March 29, 2007 One way is <?php $src = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ'; $len = strlen($src) - 1; $str = ''; for($i=0; $i<24; $i++) { $x = rand(0,$len); $str .= $src{$x}; } echo $str; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.