A
A
Alexey Skobkin2011-01-19 16:56:55
Algorithms
Alexey Skobkin, 2011-01-19 16:56:55

Unique URL generation?

There is a need to generate a unique URL in the php + mySQL bundle like bit.ly or clck.ru.
What are the options? Unixtime generation, hashes?
The URL needs to be short, so the most banal version with MD5 disappears immediately. The option with a digital id is bad because at first the links will be short, and then lengthen. Yes, and there will be "Geta". We need such an option that "everyone is equal."

Answer the question

In order to leave comments, you need to log in

6 answer(s)
B
Bright, 2011-01-19
@skobkin

You can find the shortener sources at these links:
code.google.com/p/phurl/
www.webresourcesdepot.com/7-open-source-and-free-url-shortener-scripts-to-create-your-own/
briancray. com/2009/08/26/free-php-url-shortener-script/
As far as I know they all work the same way. You can see a typical translation function in the phurl source:
code.google.com/p/phurl/source/browse/phurl-includes/functions.php - compressNumber function, which translates some random number into 62-decimal number system

A
agul, 2011-01-19
@agul

It all depends on how many links you plan to shorten. If there are a lot of them, then sooner or later links will appear, the abbreviated URL of which will be longer than the URL of the first links.

A
AusTiN, 2011-01-21
@AusTiN

and what prevents you from taking MD5 from the current unixtime and cutting it to length, taking, say, the first 5 characters?

0
047, 2011-02-06
@047

Maybe this?

$unique_name = uniqid(md5(rand()), true);

D
deactivatedtheelephant, 2011-02-06
@deactivatedtheelephant

If you are making a short link service, you still need to store "long" links in the database. So for generation it is possible to use table ID.

Q
Qwerty-B, 2014-08-14
@Qwerty-B

Late, but there is an idea (suddenly someone will come in handy) - ID from the table in the 36-ary number system (0-9, az). And it is possible with other characters, with different case.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question