Here's an interesting solution. It's not perfect (just threw the code
together), but it works. It has the additional benefit of adding a
level of security to your application because it hashes your query
string in a way that cannot be reversed (essentially obfuscates it in a
non-reversible manner). It also assumes that once you have created a
shorter query string, you will eventually want to recover the original
query string, probably in the page processing the request that contains
the query string.
Start by including these two functions:
<cfscript>
function getShortString(str) {
var key = "";
if (false is isDefined("application._strMap")) {
application._strMap = structNew();
}
key = hash(str);
application._strMap[key] = str;
return key;
}
function getLongString(key) {
if (false is isDefined("application._strMap")) {
return "";
}
if (false is structKeyExists(application._strMap, key)) {
return "";
}
return application._strMap[key];
}
</cfscript>
Then create your querystrings like this:
<cfset qs = "a=b&b=c&c=a" />
<a
href="someProcessingPage.cfm?q=<cfoutput>#getShortString(qs)#</cfoutput>">click
here</a>
In the processing page, retrieve the original querystring like this:
<cfset qs = "#getLongString(url.q)#" />
The full querystring is <cfoutput>#qs#</cfoutput>.
Of course, you could do something a little more clever like creating a
function that returns a struct or parses the querystring and puts the
values in the URL scope so that you could retrieve them just as though
they were literally passed in the URL as opposed to actually getting
back a query string, but you get the idea.
Your query string has to be over 32 characters before this technique
starts to pay for itself in terms of length since the hash() function
returns a 32 byte string. As I mentioned earlier, it has the added
benefit of completely obscruing the data you pass in your query string,
too, since the MD5 hash is not reversable.
If you decide to implement something like this, consider variable locking.
Hope this helps.
Cantrell
Ian Lurie wrote:
> Hi all,
>
> I've searched the devcenter, google, etc. but can't seem to find any
> discussion of how to generate shorter URL strings. I want to take:
>
> http://www.site.com?action=blah&brand=1&name=blahblah&....
>
> And convert it to
>
> http://www.site.com/asdfwer234123
>
> I've seen it done but just can't remember where. Can someone send me a url?
>
> Thanks in advance,
>
> Ian
--
Christian Cantrell
[EMAIL PROTECTED]
(571) 220-8659 (mobile)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4
Subscription: http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Structure your ColdFusion code with Fusebox. Get the official book at
http://www.fusionauthority.com/bkinfo.cfm