I have 2 functions
This one generates numbers only
//Generate a string of only numbers.
function GenerateNUM($length)
{
$alphabet = '1234567890';
$tip = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < $length; $i ++) {
$n = rand(0, $alphaLength);
$tip[] = $alphabet[$n];
}
return implode($tip);
}
This one generates numbers and letters
//Generate a string of numbers and letters.
function GenerateAll($length)
{
$alphabet = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890';
$pass = array();
$alphaLength = strlen($alphabet) - 1;
for ($i = 0; $i < $length; $i ++) {
$n = rand(0, $alphaLength);
$pass[] = $alphabet[$n];
}
return implode($pass);
}
and I call it like this
$ValidationCode = GenerateNUM(12);
or this
$ValidationCode = GenerateAll(12);
It works great but my question is do I really need 2 blocks of code? is there a way to create one function and be able to decide if numbers and letters are called or just numbers? or am I over thinking it?