Hi, so i've made a function called GenerateKey, and i've made 2 of them to see which solution was best, and i like the second one best.
But how big is the difference on speed?
Here's the first version:
function GenerateKey($name)
{
$generated = strtoupper(md5($name).uniqid());
return rtrim(chunk_split(substr($generated, -24), 4, "-"), "-");
}
Then the second version(Which i like best):
function GenerateKey($length)
{
$random = array('q','w','e','r','t','y','u','i','o','p','a','s','d','f','g','h','j','k','l','z','x','c','v','b','n','m','1','2','3','4','5','6','7','8','9');
$serial = "";
for ($i=0; $i < $length; $i++) {
$randomChar = $random[mt_rand(0, 35)];
if(strlen($serial) < 20)
{
$serial .= $randomChar;
}
}
$key = chunk_split($serial, 4, "-");
return strtoupper(rtrim($key, "-"));
}
I know the $key variable is not needed, but i will change that later.
So how's the speed, which is fastest, i bet the first one but i just like the second one best,
and the result of the second one is so much better.
:-)