Skip to content

Instantly share code, notes, and snippets.

@grimmdev
Last active August 19, 2016 08:34
Show Gist options
  • Save grimmdev/394e903cf50ba8c65af2 to your computer and use it in GitHub Desktop.
Save grimmdev/394e903cf50ba8c65af2 to your computer and use it in GitHub Desktop.
CD Key Generator!
// Sean Loper
// I use a template so any combination can be used, logically.
// Every X is replaced by a random character while 9 is replaced by a random number!
function randomKey()
{
$template = 'XX99-XX99-99XX-99XX-XXXX-99XX';
$k = strlen($template);
$sernum = '';
for ($i=0; $i<$k; $i++)
{
switch($template[$i])
{
case 'X': $sernum .= chr(rand(65,90)); break;
case '9': $sernum .= rand(0,9); break;
case '-': $sernum .= '-'; break;
}
}
return $sernum; // or echo $sernum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment