Skip to content

Instantly share code, notes, and snippets.

@shawn-crigger
Last active June 13, 2018 17:01
Show Gist options
  • Save shawn-crigger/01e9299b63affb5524fc70f9a195db7b to your computer and use it in GitHub Desktop.
Save shawn-crigger/01e9299b63affb5524fc70f9a195db7b to your computer and use it in GitHub Desktop.
Returns random characters
function _make_token( $length = 16 )
{
$token = "";
$codeAlphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
$codeAlphabet.= "abcdefghijklmnopqrstuvwxyz";
$codeAlphabet.= "0123456789";
$max = strlen($codeAlphabet); // edited
for ($i=0; $i < $length; $i++) {
token .= $codeAlphabet[random_int(0, $max-1)];
}
return $token;
}
<?php
$length = 8;
$x = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$name = substr( str_shuffle( str_repeat( $x, ceil( $length / strlen( $x ) ) )), 1, $length );
$name = str_replace( array( '!', '@', '#', '$', '%', '^', '&', '*', '(', ')', ), '', $name );
$two = substr( $name, 0, 2 );
$path = $root . $two . '/';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment