Posted By

mattkenefick on 05/20/08


Tagged

random generator key create


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

luman
fackz


PHP: Random Key Generator


 / Published in: PHP
 

Creates a variable length key from a pre-defined set of characters.

  1. function createRandomKey($amount){
  2. $keyset = "abcdefghijklmABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  3. $randkey = "";
  4. for ($i=0; $i<$amount; $i++)
  5. $randkey .= substr($keyset, rand(0, strlen($keyset)-1), 1);
  6. return $randkey;
  7. }

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: iloveitaly on June 24, 2009

count($keyset) should be strlen($keyset)

You need to login to post a comment.