How do you compress a url for ascii output?

Discussion in 'Perl Misc' started by blaine@worldweb.com, Sep 11, 2006.

  1. Guest

    Hello,

    I've been trying to come up with a way to compress part of a url to
    make it shorter.

    Below I have an example of a variable for my url and want it smaller
    sized ascii. I've been trying the Compress:Zlib, however this doesn't
    output ascii.. Any ideas?

    use Compress::Zlib;

    #------ deflate -------
    my ($out, $out1, $status, $nout);
    my $x = deflateInit() or die "this text has been deflated/inflated";

    my $testStream =
    "CIAQEDEUDVvVEwEEChDtDaAVCHAhBFANADBeAlEqCvDrCgDHDeDyClBREgBSCFEdBIBbDeCYACBLEWAwEaEECMBjBvCEBiEbCCCgABEAElBNCsEYDFCODEEoECDaDgADCtEhBpAOCACGDECsCfBsCPAaBhAaDeDTECERBdEIBuEiEjDqCgEQBPDjBQAEEjDtDFCMDaDfAuCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC";
    ($out,$status) = $x->deflate($testStream);

    $status == Z_OK or die "deflation failed\n";
    ($out1, $status) = $x->flush();

    $out .= $out1;


    $status == Z_OK or die "deflation failed\n";
    print "deflated output: [$out]\n";
     
    , Sep 11, 2006
    #1
    1. Advertising

  2. >>>>> "blaine@worldweb" == blaine@worldweb com <> writes:

    blaine@worldweb> I've been trying to come up with a way to compress part of a url to
    blaine@worldweb> make it shorter.

    Learn to use server-side sessions. You don't need a 256-char URL. Ever.
    That's more possibilitities than countable atoms in the universe. You clearly
    don't have *that* much state to distinguish. :)

    --
    Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    <> <URL:http://www.stonehenge.com/merlyn/>
    Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

    --
    Posted via a free Usenet account from http://www.teranews.com
    Warning: Do not use Ultimate-Anonymity
    They are worthless spammers that are running a scam.
     
    Randal L. Schwartz, Sep 11, 2006
    #2
    1. Advertising

  3. Guest

    Sorry, maybe I was not clear.

    My url is actually not 256 char's. It's actually very short, however
    there is encrytped variable data that I would like to shorten.

    ie.
    www.testurl.com/script.html?encrypt...uCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC


    So I would like a much shorter encryptedString part

    ie
    www.testurl.com/script.html?encryptedString=<40 - 60% shorter then the
    original>




    Randal L. Schwartz wrote:
    > >>>>> "blaine@worldweb" == blaine@worldweb com <> writes:

    >
    > blaine@worldweb> I've been trying to come up with a way to compress part of a url to
    > blaine@worldweb> make it shorter.
    >
    > Learn to use server-side sessions. You don't need a 256-char URL. Ever.
    > That's more possibilitities than countable atoms in the universe. You clearly
    > don't have *that* much state to distinguish. :)
    >
    > --
    > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
    > <> <URL:http://www.stonehenge.com/merlyn/>
    > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
    > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    >
    > --
    > Posted via a free Usenet account from http://www.teranews.com
    > Warning: Do not use Ultimate-Anonymity
    > They are worthless spammers that are running a scam.
     
    , Sep 11, 2006
    #3
  4. Scott Bryce Guest

    wrote:

    > Sorry, maybe I was not clear.
    >
    > My url is actually not 256 char's. It's actually very short, however
    > there is encrytped variable data that I would like to shorten.


    Randal's comments still apply. You don't need to keep 256 characters
    worth of state.

    If we know what you were really trying to accomplish, perhaps we could
    help you find a better way to do it, or refer you to another newsgroup
    where this would be on-topic.

    What is the purpose of the variable data? Why are you passing it in as
    part of the URL? Why does it need to be so long?
     
    Scott Bryce, Sep 11, 2006
    #4
  5. Ted Zlatanov Guest

    On 11 Sep 2006, wrote:

    > I've been trying to come up with a way to compress part of a url to
    > make it shorter.
    >
    > Below I have an example of a variable for my url and want it smaller
    > sized ascii. I've been trying the Compress:Zlib, however this doesn't
    > output ascii.. Any ideas?


    Use a web service like http://makeashorterlink.com/

    Otherwise you just can't compress a URL to a valid URL equivalent to
    the original (unless I misunderstand your question).

    Ted
     
    Ted Zlatanov, Sep 11, 2006
    #5
  6. Scott Bryce Guest

    wrote:

    > Below I have an example of a variable for my url and want it smaller
    > sized ascii. I've been trying the Compress:Zlib, however this doesn't
    > output ascii.. Any ideas?



    Do a Zlib compression, then Base64 the result. It will grow when you
    Base64 it, but hopefully not back to its original size.
     
    Scott Bryce, Sep 11, 2006
    #6
  7. Guest

    wrote:
    > Hello,
    >
    > I've been trying to come up with a way to compress part of a url to
    > make it shorter.
    >
    > Below I have an example of a variable for my url and want it smaller
    > sized ascii. I've been trying the Compress:Zlib, however this doesn't
    > output ascii.. Any ideas?
    >
    > use Compress::Zlib;
    >
    > #------ deflate -------
    > my ($out, $out1, $status, $nout);
    > my $x = deflateInit() or die "this text has been deflated/inflated";
    >
    > my $testStream =
    > "CIAQEDEUDVvVEwEEChDtDaAVCHAhBFANADBeAlEqCvDrCgDHDeDyClBREgBSCFEdBIBbDeCYACBLEWAwEaEECMBjBvCEBiEbCCCgABEAElBNCsEYDFCODEEoECDaDgADCtEhBpAOCACGDECsCfBsCPAaBhAaDeDTECERBdEIBuEiEjDqCgEQBPDjBQAEEjDtDFCMDaDfAuCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC";
    > ($out,$status) = $x->deflate($testStream);
    >
    > $status == Z_OK or die "deflation failed\n";
    > ($out1, $status) = $x->flush();
    >
    > $out .= $out1;
    >
    >
    > $status == Z_OK or die "deflation failed\n";
    > print "deflated output: [$out]\n";


    Any reason your not passing it as a form variable instead?

    There is a module for sticking Storable's in HTML. You might take a
    look at that. There is also a length limit difference between POST and
    GET if I'm not mistaken.

    Personally I compress, DES encrypt, Base32 encode and stick it in in
    hidden form attribute. Of course that would crush the CPU if the site
    ever got popular. But hey, CPU is cheap.

    -Matt
     
    , Sep 12, 2006
    #7
  8. On 2006-09-12 03:23, <> wrote:
    > wrote:
    >> I've been trying to come up with a way to compress part of a url to
    >> make it shorter.
    >>
    >> Below I have an example of a variable for my url and want it smaller
    >> sized ascii. I've been trying the Compress:Zlib, however this doesn't
    >> output ascii.. Any ideas?

    [...]
    > Any reason your not passing it as a form variable instead?


    What is a "form variable"? Forms can be submitted via GET or POST
    requests. In a GET request, the variable becomes part of the URL, in a
    POST request it is submitted as part of the body.

    So you probably wanted to ask "Any reason not to use POST requests?"

    There are a couple of reasons:

    1) There is a semantic difference between GET and POST requests. GET
    requests are supposed to only retrieve information from the server,
    and not to change the server state. Hence they are cacheable and a
    browser may automatically repeat them if the result is not in the
    cache any more. A POST request is intended change the state of the
    server. Hence the browser must sent every request exactly once to the
    server.

    2) POST requests are not bookmarkable.

    3) Search engines don't issue POST requests.

    hp

    --
    _ | Peter J. Holzer | > Wieso sollte man etwas erfinden was nicht
    |_|_) | Sysadmin WSR | > ist?
    | | | | Was sonst wäre der Sinn des Erfindens?
    __/ | http://www.hjp.at/ | -- P. Einstein u. V. Gringmuth in desd
     
    Peter J. Holzer, Sep 12, 2006
    #8
  9. John Bokma Guest

    "" <> wrote:

    > Hello,
    >
    > I've been trying to come up with a way to compress part of a url to
    > make it shorter.
    >
    > Below I have an example of a variable for my url and want it smaller
    > sized ascii. I've been trying the Compress:Zlib, however this doesn't
    > output ascii.. Any ideas?


    use base64 encoding on the compressed data, which might work when the
    compression works well. Other, and maybe better option, is using sessions
    and using the session id in the URL.


    --
    John Experienced Perl programmer: http://castleamber.com/

    Perl help, tutorials, and examples: http://johnbokma.com/perl/
     
    John Bokma, Sep 13, 2006
    #9
  10. Ted Zlatanov Guest

    On 11 Sep 2006, wrote:

    > Sorry, maybe I was not clear.
    >
    > My url is actually not 256 char's. It's actually very short, however
    > there is encrytped variable data that I would like to shorten.
    >
    > ie.
    > www.testurl.com/script.html?encrypt...uCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC
    >
    >
    > So I would like a much shorter encryptedString part
    >
    > ie
    > www.testurl.com/script.html?encryptedString=<40 - 60% shorter then the
    > original>


    If you want to make the URL self-sufficient, use a database table.

    http://www.testurl.com/script.html?encryptedString=[UNIQUE ID HERE]

    and then on the server save this string with a unique ID in a 2-column
    database table. You can use sqlite or something similar if you don't
    already have a database server running, and want the operation to be
    fast. Just increment the ID when a new string is added.

    If you expect lots of strings, prune the database table occasionally
    or on a schedule (though this, of course, depends on your setup and
    needs).

    Ted
     
    Ted Zlatanov, Sep 13, 2006
    #10
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. ixtahdoom
    Replies:
    0
    Views:
    564
    ixtahdoom
    Jun 15, 2004
  2. =?Utf-8?B?15nXldeg15kg15LXldec15PXkdeo15I=?=

    Do you know good zip (compress files) control?

    =?Utf-8?B?15nXldeg15kg15LXldec15PXkdeo15I=?=, May 23, 2005, in forum: ASP .Net
    Replies:
    6
    Views:
    487
    Kevin Spencer
    May 24, 2005
  3. TOXiC
    Replies:
    5
    Views:
    1,265
    TOXiC
    Jan 31, 2007
  4. James O'Brien
    Replies:
    3
    Views:
    258
    Ben Morrow
    Mar 5, 2004
  5. Alextophi
    Replies:
    8
    Views:
    522
    Alan J. Flavell
    Dec 30, 2005
Loading...

Share This Page