I'm trying to create reference numbers for customers and orders based on this answer with the following requirements:
- All numbers
- Unique (as possible without checking the database)
- Same length
- Customers start with 10
- Orders start with 20
Here is my current code for a customer ref:
$ref = uniqid();
$decimalRef = hexdec($ref);
$finalRef = 10 . $decimalRef;
Is this a good solution? I'm worried about uniqueness and not sure if they will always be the same length.
Update
I don't want to use a database auto increment value because I don't want to write to the database beforehand, and I don't want my customers knowing they are my customer number 2. For obvious reasons.
Update 2
If I was to use a database auto-increment value, how do I then convert this into a more appropriate customer facing number as per the requirements (same length, starting with 10). If I only have 4 orders in the system, I don't want to announcing that to my users.