PHP: Random Key Generator


/ Published in: PHP
Save to your folder(s)

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


Copy this code and paste it in your HTML
  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

You need to login to post a comment.