Good afternoon I have the following code to generate a sequence of letters and numbers.
function aleatorio($longitud, $tipo=0){
$codigo = "";
$caracteres="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
$max=strlen($caracteres)-1;
for($i=0;$i < $longitud;$i++)
{
$codigo.=$caracteres[rand(0,$max)];
}
return $codigo;
}
and I call the function to give me a random.
My new problem is that I need to create a random one and check that it does not exist in the database and I do not know how to do it, the idea is that it is a unique random in the database.