-2

I current have a URL like this

http://blahblah.com/process.php?q=[HUGEEEEEEEEEEEEEEEEEEEEEEEE STRING of 5000 chars]

My goal is to convert this something like

http://blahblah.com/process.php?q=[less charcters]

The first question:

How do I perform a function (encryption function for instance) on my GET variables before it is sent to the action page?

I've seen many questions asked with a similar topic.

The second question:

Assuming, I can do the above by some means (maybe by jQuery/JavaScript or something). How do I compress in the index.php page and decompress in the process.php page?

My attempt:

Searching for functions with fixed lengths:

I've looked at some encryptions that maintain the string size for ex. md5() gives a standard length that is short and tidy even for an extremely huge string. But unfortunately md5 cannot be decoded easily. Is there any other such function that I decode and which has a fixed length? If so, I could use that assuming I know a way to do Step 1.

EDIT: I write a request not to mark as a duplicate of that question and a question which hasn't been answered have specifically been asked again.. Please read @Jeremy 's comments, he was following this post.

  • It would help to know what, exactly, you are trying to achieve. And I don't mean "encrypting POSTdata", because that's what SSL is for. I mean, what is your project goal? As it stands, this question screams "XY problem" to me. – Niet the Dark Absol Jun 14 '14 at 21:34
  • As an FYI: POST data is not in the URL (that's GET data). –  Jun 14 '14 at 21:34
  • @Niet I hope I made it clear :) – user3739937 Jun 14 '14 at 21:47
  • @Jeremy I'm sorry.It has been corrected. – user3739937 Jun 14 '14 at 21:47
  • OK. Why, though, would you want to have 5K characters in the URL? If memory serves, you can't anyway. If it requires that much data, why spend time compressing and decompressing when you can POST it? –  Jun 14 '14 at 21:53
  • Its not that huge anyway. Around 2.2k characters which is reasonable for my script. I can't pass it over GET as it gives the error saying "URL too long". That is why I need a way to reduce the character count. – user3739937 Jun 14 '14 at 21:58
  • The length of your string is making it so google won't index this page, in case you care. Max is 2048. – Ohgodwhy Jun 14 '14 at 21:58
  • If you can't post it over GET, what is stopping you from POST? Why the love affair with GET? ;) –  Jun 14 '14 at 22:05
  • Well, to be honest, I want my user to have the option to share this page or facebook for instance and hence give him a static webpage which is not possible with POST. Also, for many other reasons that my code relies on. @Ohgodwhy If I can get an answer to my question, I don't see any point in your question. – user3739937 Jun 14 '14 at 22:13
  • 2
    @user3739937 then generate a specific url and save the string into the database, and then make a comparison based on the url. – Ohgodwhy Jun 14 '14 at 22:21
  • That has more server round trips. I will ultimately have to consider that option as my last resort if no other smart solution is given :( – user3739937 Jun 14 '14 at 22:30
  • 2
    That *is* the smart solution. If a page requires a 2.2K long string to represent it, something is wrong. –  Jun 14 '14 at 22:54
  • This question is incorrectly flagged as a duplicate of the question linked to as prior. Those flagging didn't read one or the other, unfortunately. –  Jun 15 '14 at 03:44
  • I'm voting to reopen this as not a duplicate, but @user3739937 your last comment and the tone of your edit (which are basically just anti-SO snark) are not going to win you any favors on this site. – Thomas Jun 15 '14 at 08:39
  • @Thomas I'm sorry for being arrogant there.I was just disappointed that in spite of me telling in advance, they didn't even care to look at it once more :( Please reopen this. I've gone through the duplicate and it has just information and NO answer to the question. Thanks, JJ – user3739937 Jun 15 '14 at 11:39

2 Answers2

3

I personally think it is best to use POST to send the data to the page. I am pretty much sure you can not use anything like MD5 to 'compress' the data because what MD5 does is hash the data, so it will look at your data run an algorithm to create this fixed length hash.

However, there is an extremely small possibility that two data sets will create the same hash, therefore it seems to me impossible to reliably decrypt MD5 or other similar hashes. Check out this page for more on hash collisions.

Giacomo1968
  • 25,759
  • 11
  • 71
  • 103
3

Your problem is that you are using the internet the wrong way. The URL is limited (and it depends on the browser), so don't event to try to use long URLs - even when you want to shorten it.

Please keep in mind, that we are using the WordWideWeb for a long time and if you come into a deadend you just have to rethink your problem. Maybe you are using your current technology the wrong way.

So, use POST instead to transfer your data (as others mentioned before).

If you want to "compress" your data you should use a zip like thing and then you must make that URL confirm like BASE64 afterwards. This is not suitable in any way and completly hideous. (And of course it can not guarantee the length of your URL).

MD5 is a hash not a compression thing. MD5 is not reversable. Once you hash something you can not go back again. This is not a magical way to compress tons of megabytes into a single short number. This is to have a short thing that can tell if the original data was modified (if you do that twice).

See http://en.wikipedia.org/wiki/Hash_function See http://en.wikipedia.org/wiki/MD5

BTW: It is the same as How to compress/decompress a long query string in PHP?

Community
  • 1
  • 1
Raxa
  • 372
  • 3
  • 7
  • Very well put for a non-native English speaker, Raxa. +1 and I look forward to your continued contributions. –  Jun 15 '14 at 03:37