Random String Generator
This PHP function generate a random string of a particular length and is very useful to create random passwords.
<?php
// generate a random string of a particular length
function random_string($length) {
$string = "";
// random a string with at least $length characters
for ($i = 0; $i <= ($length/32); $i++)
$string .= md5(time() + rand(0, 99));
// start point limit
$max_start_index = (32*$i)-$length;
// take the string
$random_string = substr($string, rand(0, $max_start_index), $length);
return $random_string;
}
?>
To use the function:
<?php // Gets a random string of length 24 $random_string = random_string(24); ?>
Publication details
Category: PHP
Published by: loryzz on date: 17.03.2008 21:07:15
Last edit by: loryzz on date: 02.04.2008 16:54:26
Ratings
Leave a comment
All comments must be approved by site administrator.
Please write comments on topic. Spam will be never approved.
PHP: Linked articles
Echo, Print e Heredoc published by loryzz in PHP
























Ritorna all'inizio
Based total comments
0 %
Comments percentage
0 %