Question

I have the following very simple if/else statement:

<cfif Server.ColdFusion.ProductVersion GTE "7">
        <cfoutput>#encrypt("Test text", "77qidrWFoQg96taobooCm3/WimS2Gcdd", "DESEDE", "Hex")#</cfoutput>
<cfelse>
        <cfoutput>#encrypt("Test text", "77qidrWFoQg96taobooCm3/WimS2Gcdd")#</cfoutput>
</cfif>

Works at it should under CF 7, 8, 9, 10 but not under CF 6 where I get the following error like it doesn't care about the <cfif> tag and executes what is meant for the greater versions of CF (>7).

enter image description here

Any idea? I tried many many many different otions and same result. CF 6 make me despair. P.S. No, my clients I write some scripts for are not going to move to a later version yet.

Was it helpful?

Solution

ColdFusion is trying to compile the page, but it cannot because you are using an invalid syntax for the encrypt function. CF 6 does not allow those arguments to be passed to encrypt. I suggest if you need to support CF6 that you use a <cfinclude> statement to include the post-CF6 code. So something like:

<cfif listfirst(server.coldfusion.productversion) gte 7>
  <cfinclude template="cf7encrypt.cfm" />
<cfelse>
  <cfinclude template="cf6encrypt.cfm" />
</cfif>

Then in the two cfm files you can include the version specific calls to encrypt. Then it will compile properly.

Another option would be to have two different CFCs that act as wrappers to encrypt (one for CF6 and one for CF7+) and then load the proper CFC and call an encrypt function. In either case, the key is to get the invalid call to encrypt() out of the main template.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top