A php method for generating 6-digit alphanumeric invitation codes with high uniqueness

can be brought into the user id, can be decoded, kneel to beg.

Php
Jul.14,2021

Do users have ID in the

database? If so, directly convert ID to hexadecimal, which can represent 16 ^ 6 users, 16777216, don't think too much.
clipboard.png
the deficiency after conversion is filled with 0, or 16 ^ 5 is added directly, and then subtracted to ensure six digits.
hexadecimal uses very few letters, you can also use 26 letters + 0,9 to represent numbers, that is, 36, six digits have 2.1 billion.

The

requirement should be that each user registers to generate a unique invitation code directly, right? What I mentioned is the only self-adding key in the database as the invitation code. It doesn't have to be random. Is that right?


6 bits, but also can be decoded. It is best to make a special table to store it, or add one more field to the user table, otherwise, your requirement that you can decode is too weird. Even with base64, you can only store a maximum of 3 digits, that is, 0-999, the insufficient preceding zeros, such as 001, and then = after base64 can be removed.


uniqid () learn about it?

Menu