Generate a unique URL?

0 like 0 dislike
39 views
There is a need to generate a unique URL in the php+mySQL type bit.ly or clck.ru.

What are the options? Generating unixtime, hashes?

Need a short URL, so banal variant with MD5 is eliminated immediately. The option of a digital id is bad because at first the links will be short, and then odonates. Yes and will "Geta". Need this option to "all equal".
by | 39 views

6 Answers

0 like 0 dislike
Use these links to find the source of cakrawala:
\rcode.google.com/p/phurl/
\rwww.webresourcesdepot.com/7-open-source-and-free-url-shortener-scripts-to-create-your-own/
\rbriancray.com/2009/08/26/free-php-url-shortener-script/
\r
As far as I know, they all work on the same principle. A typical function for a translation can see in the source code phurl:
\rcode.google.com/p/phurl/source/browse/phurl-includes/functions.php function compressNumber, which is a random number translates to 62 hexadecimal number system
by
0 like 0 dislike
It all depends on how many links you plan to cut. If there are many, sooner or later there will be links, shortened URL which is longer than the first URL links.
by
0 like 0 dislike
and what hinders to take the MD5 of the current unixtime and trim the length, to take, say, the first 5 characters?
by
0 like 0 dislike
Maybe this?
\r
$unique_name = uniqid(md5(rand()), true);
by
0 like 0 dislike
If you are doing the service of short links, you still need to store in the database the "long" links. So to generate you can use the ID of the table.
by
0 like 0 dislike
Later, but there is the idea (maybe useful to someone) - ID from table 36, we used the hexadecimal notation (0-9, a-z). And you can still with other characters, with different casing.
by

Related questions

0 like 0 dislike
3 answers
asked Apr 25, 2019 by Pavel_Timofeev
0 like 0 dislike
1 answer
0 like 0 dislike
6 answers
0 like 0 dislike
2 answers
110,608 questions
257,186 answers
0 comments
32,866 users