Random string generator


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



Copy this code and paste it in your HTML
  1. function str_makerand($length, $useupper, $usespecial, $usenumbers) {
  2. $charset = "abcdefghijklmnopqrstuvwxyz";
  3. if ($useupper)
  4. $charset .= "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  5. if ($usenumbers)
  6. $charset .= "0123456789";
  7. if ($usespecial)
  8. $charset .= "~@#$%^*()_+-={}|]["; // Note: using all special characters this reads: "~!@#$%^&*()_+`-={}|\\]?[\":;'><,./";
  9. if ($length == '' || $length == 0)
  10. $length = mt_rand(10, 40);
  11. for ($i = 0; $i < $length; $i++)
  12. $key .= $charset[(mt_rand(0, (strlen($charset) - 1)))];
  13. return $key;
  14. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.