note 35652 rejected from function.rand by pollita

From: Date: Wed, 10 Sep 2003 05:20:13 +0000
Subject: note 35652 rejected from function.rand by pollita
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-55913@lists.php.net to get a copy of this message
Note Submitter: Clicker ---- Most of the posts here are about generating passwords, and thats fine, but I wanted to point out something I saw as I glanced through a few of your functions... I'm using the function below as an example but I saw 3 others that had the same problem... the line in the for loop will generate an error because remember when your using a variable as an array 0 is the first entry so strlen($A) - 1 must be used in this case function GenPass($_maxlen) { $A = "abcdefghijklmnopqrstuvwxyz0123456789"; for ($i=0;$i<=$_maxlen;$i++) { $code .= $A[rand(0,strlen($A))]; // change this line to: // $code .= $a[rand(0,strlen($A)-1)]; } return $code; }

« previous php.notes (#55913) next »