How to use uniqid to generate an identifier of length 6 characters?

There is a section on my website that generates a unique identifier for each message, and then sends it to the database. The problem is that the generated identifier is 16 characters long and I only need 6 characters.

This is the code used to generate the identifier:

$order_id  = uniqid(rand(10,1000), false);

Is there a way I could make such a change?

+3
source share
1 answer

Why not do it with auto_incremental in the database? So the first id is 1, then 2, and so on. If you need only 6 digits, this will result in 999,999 different keys.


, substr(), 6 uniqid(), 100% . uniqid , WHOLE . , .

+20

All Articles