Below is the code for random string generation, it is working but there is some problem here which I at the moment cant figure out what happens here is that it always returns me value of length 1 ,I am expecting a random string of length 10. Also I am passing 10 as length. Kindly guide me what am I doing wrong here.
<?php
function random_string($length) {
$len = $length;
$base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456789";
$max = strlen($base) - 1;
$activatecode = '';
mt_srand((double) microtime() * 1000000);
while (strlen($activatecode) < $len + 1) {
$activatecode.=$base{mt_rand(0, $max)};
return $activatecode;
}
}
?>