Last Updated: February 25, 2016
·
963
· chris15001900

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;

}