Unique code after php link
I want to create a way for images to generate a short link such as domain.com/9t6So63
I want to make it 8 chars long after domain.com/ long and accept
0123456789abcdefghijklmnopqrstu开发者_高级运维vwxyz
how many total generated links could i get out of this? And should i make it more?
0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ
This is a 62 characters longs string.
If your problem is only to know the number of links you can generate, it's no more than a simple Math problem :
62^8 = 218,340,105,584,896
how many total generated links could i get out of this?
You would get 62^8 combinations from this.
You could use uniqid() to generate the unique string. This string is generated based on a current time in microseconds so beware if you have multiple server instances generating the id at the same microsecond.
With an empty prefix, the returned string will be 13 characters long. If more_entropy is TRUE, it will be 23 characters.
Number of links are defined by the number of available characters and the length of that string, you've got twenty-six letters and ten numbers available for each position, and you're able to use each character more than once, so:
368 = 2821109907456
If you're able to use upper-case characters as well, then you've got 62 available characters for each of the eight positions, which gives a range of 628 (2821109907456) possible combinations.
This is not just a php problem, this is about combination.
The number of generate "links" changes if you want to repeat or not the chars in the chosen subset.
精彩评论