How do you compress a url for ascii output?

B

blaine

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";
 
R

Randal L. Schwartz

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. :)
 
B

blaine

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?encryptedString=CIAQEDEUDVvVEwEEChDtDaAVCHAhBFANADBeAlEqCvDrCgDHDeDyClBREgBSCFEdBIBbDeCYACBLEWAwEaEECMBjBvCEBiEbCCCgABEAElBNCsEYDFCODEEoECDaDgADCtEhBpAOCACGDECsCfBsCPAaBhAaDeDTECERBdEIBuEiEjDqCgEQBPDjBQAEEjDtDFCMDaDfAuCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC


So I would like a much shorter encryptedString part

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

Scott Bryce

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?
 
T

Ted Zlatanov

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
 
S

Scott Bryce

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.
 
S

shrike

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
 
P

Peter J. Holzer

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
 
J

John Bokma

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.
 
T

Ted Zlatanov

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?encryptedString=CIAQEDEUDVvVEwEEChDtDaAVCHAhBFANADBeAlEqCvDrCgDHDeDyClBREgBSCFEdBIBbDeCYACBLEWAwEaEECMBjBvCEBiEbCCCgABEAElBNCsEYDFCODEEoECDaDgADCtEhBpAOCACGDECsCfBsCPAaBhAaDeDTECERBdEIBuEiEjDqCgEQBPDjBQAEEjDtDFCMDaDfAuCwEfChCmEmDtDRDlBdBYACBkDYEpEnDoCMAJETEcDxEC


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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,983
Messages
2,570,187
Members
46,747
Latest member
jojoBizaroo

Latest Threads

Top