Random string in php
Here's a function to create a random string dependent on time:
function generateString($length) {
$chars = 'ABCDEFGHIJKLMNOPRSTUWXYZabcdefghijklmnoprstuwxyz1234567890';
$generated = '';
$time = time();
$generated .= $time;
$gL = strlen($generated);
if($gL >= $length) return substr($generated, 0, $length);
for($i=0; $i<$length-$gL; $i++) {
$generated = $chars[rand(0,strlen($chars)-1)] . $generated;
}
return $generated;
}
Written by Krzysztof
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#