Welcome Guest, Not a member yet? Register   Sign In
Implementation of encrypt->encode() that doesn't include characters in the result?

I'm currently using the Encryption class for placing things like database record primary keys into hidden form fields and the like by way of the encode() function. It's working quite well as someone viewing the source of the page will see things like:
However, a handful of my controller functions that get run via AJAX calls also take these encoded keys as parameters, and very occasionally the encoded value includes a slash. Naturally, CI will interpret that as multiple parameters and I only get part of the value into my function.

The appearance of '=' and '+' in the encoded values prompted me to just add those two characters to my allowed URI character list (as hesitant as I was to do so), but of course I can't do that with '/'. Is there any way, perhaps by changing the cipher used by the Encryption class, to still use encode()/decode() for my purposes without having to worry about slashes appearing in the values? Or do I need to look at implementing my own encode()/decode() pair?

I had considered sticking the various keys (there can be dozens on a single loaded page) into session variables, but that would amount to a bit of a headache managing which ones were set and where.


This doesn't really answer your question but what about a 3rd option, I don't know what you're using to do your AJAX calls but can you alter it to use POST instead of GET? It's a fairly trivial thing to do if you're using prototype just specify the method as post when setting up the new Ajax.Request.

- K

Hmm, I never even considered that as I use Ajax.Updater and the docs for it don't go into quite as much detail on the Ajax Options available as Ajax.Request's docs do. Wink Considering POST is the default method, I'm already half way there.

I'll give it a shot, see if it works out.

Yep, that did indeed do the trick. Thanks a bunch kgill!

For the reference of others, my resultant code snippet in my anchor element is
onclick="new Ajax.Updater( "VRgFBFZIAkFTH1YLUF4IZQk+ADYIbAE4VDVUMVBgAWA=", "/common/cancel", { parameters: 'key=VRgFBFZIAkFTH1YLUF4IZQk+ADYIbAE4VDVUMVBgAWA=' });
(I use the encoded key as the id of the page element I'm updating as well, which is why it's in there as the first parameter to Ajax.Updater as well)

Theme © iAndrew 2016 - Forum software by © MyBB