How can I generate a 6 digit unique number? I have verification mechanisms in place to check for duplicate entries.
But with a six digit code, there are 1 million possible combos, making it a lot tougher for someone to crack your security code.
$six_digit_random_number = random_int(100000, 999999);
As all numbers between 100,000 and 999,999 are six digits, of course.
If you want it to start at 000001
and go to 999999
:
$num_str = sprintf("%06d", mt_rand(1, 999999));
Mind you, it's stored as a string.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With