开发者

is there a way to compress a GET string so it won't be so long?

I need to compress a string so it is shorter for a GET method form. Is there any way to compress a string and it will be decrypted later? That way...

?error=LOTS OF STUFFLOTS OF STUFFLOTS OF STUFFLOTS OF STUFFLOTS OF STUFF

is shorter in some sort of key

?error=someke开发者_JAVA技巧y

so I can get back the result later. Not using MySQL preferably.

Anyone know a good method for this?

Update: To clarify, I am using a GET because this is a cross site include and a POST will not be accepted into the variable scope of the HTTP included file.


If you're using PHP, the easiest way to send an error message is with the $_SESSION. Simply say session_start(); at the top of the pages, and say $_SESSION['error'] = "TEXT";. Then isset($_SESSION['error']);.

Of course, you could always use $_POST.


I'd use POST instead... Or, come up with your own key mapping (error=1 would map to a long wordy error - like Col. Shrapnel's example).

You could also use a hash table. http://en.wikipedia.org/wiki/Hash_function


Easiest way to make your GET string shorter. Use POST.

(Update: Again, if you control how the form is sent, use POST. Use it. Don't use GET. To be clear, if you can use POST.)

But perhpas you need to pass this data as a regular old link. In that case I guess you could try php's compression functions. Some of the operate directly on strings.

For example, gzcompress() and gzuncompress() could be used to compress/uncompress a string. From the php manual:

<?php
  $compressed   = gzcompress('Compress me', 9);
  $uncompressed = gzuncompress($compressed);
  echo $uncompressed;
?>

Of course you'll have to run it through urlencode() and urldecode() - which since I'm sure the compression algorithms will output binary data, may not really save you anything.

Or it may not work at all. Would be interesting to try.

Update: Tested, it's crazy, but it did make your example string smaller.


Not really 'on-the-fly', You might be able to Gzip and then base64 encode, (but base64 encoding increases the size, I just don't know how much)

But really, if you are exceeding the GET size, you should probably just switch to POST.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜