Skip to content

Instantly share code, notes, and snippets.

@CrowderSoup
Created August 9, 2012 20:55
Show Gist options
  • Save CrowderSoup/3307964 to your computer and use it in GitHub Desktop.
Save CrowderSoup/3307964 to your computer and use it in GitHub Desktop.
PHP Random String Generator
<?php
function get_rand_str($length)
{
$chars = array_merge(range('a','z'), range('A','Z'), array('!','@','#','$','%','&','*'));
$length = intval($length) > 0 ? intval($length) : 16;
$max = count($chars) - 1;
$str = "";
while($length--) {
shuffle($chars);
$rand = mt_rand(0, $max);
$str .= $chars[$rand];
}
return $str;
}
echo (get_rand_str($_GET['len']));
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment