How do I use uniqid to generate a 6 chars length ID?
php, random, unique
Solution
Why not do this with auto_incremental in the database? So the first id is 1, then 2 and so on. If you only need 6 digits this will result in 999 999 different keys.
The previously accepted answer here, using `substr()` to take the first 6 characters from `uniqid()`, is not 100% safe. `uniqid` will product a unique id where the WHOLE id will be unique. By removing these characters you may end up with duplicates.
Problem
My website has a section that generates a unique id for every post and then it's sent to the database. The problem is that the ID that is generated totals 16 chars in length and I need the id to be 6 chars only. This is the code that is used to generate the ID: ``` $order_id = uniqid(rand(10,1000), false); ``` Is there any way that I could accomplish such a change?