Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Shorten Url/Link Param

by hankcoder (Scribe)
on Dec 05, 2017 at 05:53 UTC ( #1204921=perlquestion: print w/replies, xml ) Need Help??
hankcoder has asked for the wisdom of the Perl Monks concerning the following question:

I would like to convert a long url or long link parameter string into short url or short string. I have tried using WWW::Shorten 'TinyURL' but it will remotely connect to external server for some reason. Furthermore, the shorten url will always have prepended which I would like to use my own so I can fully take control how to manage url.

Is it possible to do this shortening task internally? My main reason is I created my own url link to my own page but it contain some long encoded strings. Eg I would like to make it a kind of short "alias" so it looks better for user eg[short encoded params]

I also tried using Short::URL but it takes integer value instead of a string. Perhaps I'm not quite understand how to use this encode statement my $encoded = $su->encode(10000);

I also tried to find some long string encoding method but to not avail.

Could anyone please give me some suggestions or any better solutions to this. Your help are greatly appreciated. Thanks.

Replies are listed 'Best First'.
Re: Shorten Url/Link Param
by thomas895 (Chaplain) on Dec 05, 2017 at 06:41 UTC

    There are a variety of ways to accomplish this. The most straight-forward way is to run some free/open source URL shortener elsewhere on your server, and have your application use its API to generate short links.
    Another way is to make a table in your database mapping some kind of ID (could be a SHA-1 of the original URL or state, or some kind of unique ID, or ...) to the URL or application state. When loaded, load that state and continue from there.

    "Excuse me for butting in, but I'm interrupt-driven..."

      Thanks for reply Thomas. So the actual shorten url method is just an unique ID pointing to the long Url/string that being associated to? If this is the case, then I have misunderstood the whole "shortening" method wrongly. I thought it is some kind of encoding and decoding method.

      Could you further clarify on this? Generating a unique random short string and associating it to my long url/string is pretty much straight forward.

        Yes, this is a translation process not encode/decode. It is not possible to compress (encode) a long URL into a much shorter one and have enough information to recreate the long URL from only the very short URL. There needs to be a translation hash table. For reference see Wiki Tiny Url.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1204921]
Front-paged by haukex
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (12)
As of 2018-10-16 15:02 GMT
Find Nodes?
    Voting Booth?
    When I need money for a bigger acquisition, I usually ...

    Results (85 votes). Check out past polls.