Automatic Redirect to Secure Site

A combination lock Its not that this is really all that hard to do, but a common security issue is to make sure that users are going to a HTTPS version of a site. This code snippet handles automatic redirection of a user from the unsecured version of a page to the secured version.

<!--- See if HTTPS is off --->
<cfif cgi.https eq "off">
    <!--- Get site and path --->
    <cfset location = "https://" & cgi.http_host & cgi.script_name />
    
    <!--- See if there are any URL params --->
    <cfif len(cgi.query_string)>
        <!--- Append the URL params --->
        <cfset location = location & "?" & cgi.query_string />
    </cfif>
    
    <!--- Redirect to the secure verion --->
    <cflocation url="#location#" />
</cfif>

As a side effect, it also blocks POSTs to the unsecured version. I'm not sure if thats a feature or a bug though.

 

CF on Wheels: What I Like

CF on Wheels LogoOver the last few days, I've taken the time to make myself a little more familiar with CF on Wheels, and I've I'm really digging it. CF on Wheels bills itself as a ColdFusion framework "in the spirit of Ruby On Rails," and I think it lives up to the tag line. Click "more" to read more about it.

 

[Macromedia][SQLServer JDBC Driver]Object has been closed.

I got this error for the first time today, while trying to get a query working in ColdFusion 8.01. I'd defined some custom functions in SQL Server, and tested them out through the SQL Server Management Studio, but the datasource user didn't have the right permissions to use the queries. I added the permissions, reloaded the page and got smacked with the following error:

[Macromedia][SQLServer JDBC Driver]Object has been closed.

I found the solution on House of Fusion: restart your ColdFusion services. Something about the lack of permissions seems to catch in CF, and wont be released until you restart.

 

Regex Tester Link

Thank you to the anonymous person that let me know that the link I had to my ColdFusion 8 and Java Regex Tester setup wasn't working. During my redesign the link got smashed, and I had missed it.

For reference, its new home is http://www.jonhartmann.com/regex.cfm, or you can click here to view the ColdFusion 8 and Java Regex Tester

 

Utility Function: Singularize()

Well, after doing pluralize(), it should be no surprise that I also wanted to do singularize(). There are actually more rules for this one, even though I tried harder to make the rules smarter, rather then more numerous. In the end, the code is identical, save for the different list of patterns to match. Again, these patterns are based on the singularization regular expressions I found on ThinkSharp.org, although with my own modifications. Read more to see the code and the results of testing.

 

More Fun with ArgumentCollection

So, I went back and visited the thread on AttributeCollection and ArgumentCollection I talked about back on Wednesday, and I came up with another test I wanted to look at with ArgumentCollection:


<cfset request.test = {
    value1 = "One",
    value2 = "Two"
} /
>

<cfset request.test2 = {
    value3 = "Three",
    value4 = "Four"
} /
>



<cffunction
    name="OutputArguments"
    returntype="void"
    output="true"
>

    <cfargument name="argumentCollection" type="struct" requred="false" default="#request.test2#"/>

    <cfdump var="#ARGUMENTS#" label="From OutputArguments()" />
</cffunction>

I'm not sure what I expect the result to be, but the result I got isn't it:

 

More Entries

Jon Hartmann, July 2011

I'm Jon Hartmann and I'm a Javascript fanatic, UX/UI evangelist and former ColdFusion master. I blog about mysterious error messages, user interface design questions, and all things baffling and irksome about programming for the web.

Learn more about me on LinkedIn.