in reply to Long url to tiny url.
But mainly, all you need is a database with 2 fields: realURL and tinyURL.
When someone submits a realURL asking for a tinyURL, you check to see if that realURL is already there.
If so, you give them the tinyURL that already exists for it.
If not, you use some random method to generate tinyURLs until you get one that's not already in your database, insert (realURL, tinyURL) in the database, and give them the new tinyURL.
When a tinyURL request comes in to your website, you generate an http-redirect request to the realURL.
Actually generating random strings is pretty easy -- you could just have an array of "printable" characters like
, and usemy @printable=('a'..'z','A'..'Z','0'..'9');
to generate "tiny" strings until you get one that's not in your table already...my $tiny=join "",map {$printable[rand(scalar @printable)]} 1..10;
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Long url to tiny url.
by almut (Canon) on Jul 07, 2007 at 10:03 UTC | |
by Polonius (Friar) on Jul 07, 2007 at 14:45 UTC | |
by almut (Canon) on Jul 07, 2007 at 16:10 UTC | |
by RMGir (Prior) on Jul 07, 2007 at 10:49 UTC |