coldfusionurlvariables

Hide/Encrypt URL variables in ColdFusion


If I have a website and the URL is www.example.com/mainpage.cfm?id=0123&app=2, how can I hide the id=0123 and app=2 so the user won't be able to change these variables?

I am looking at a complex program written by someone before me and he is passing these variables from page to page through the URL. I am just looking for a quick fix because I don't want to rewrite this entire program.


Solution

  • Here is how you encode it:

    #URLEncodedFormat(Encrypt(id, "#key#"))#
    

    The id is the variable, and the key can be anything (used as a certificate to encode and decode).

    To Decode:

    cfset url.id = #Decrypt(url.id, "#key#")#
    

    Again the key variable would be the same variable as the one to encode.