chapter31

development in a land far far away…

at the moment

History is not what happened. History is what was written down.

There was a recent thread on the mach-ii mailing list where a user wanted to detect whether a request was being made via http or https.

This is quite a common step developers take when working on a site with secure (SSL) and non-secure areas. As the list is mach-ii there are a couple of obvious framework specific options to take, those being Filters and Plugins. Although Peter Farrel does have an sslPlugin available, I liked the approach put forward by Matt Osbun:

Now I know a lot of people don’t like using CGI scoped variables, even the more common ones, so I thought I’d try it out with getPageContext().

As you can see it’s a little bit longer, but I believe is a safer option than relying on CGI variables.

A slight modification (using getRequest()) is testing the isSecure() which “Returns true if this protocol is secure“:

I’m still (slowly) making my way through getPageContext(), it can provide an absolute wealth of knowledge for the ColdFusion programmer. You can view the 1.4 pagecontext docs here and the servletrequest docs here.


Related Pages

4 Responses to “Detecting and redirecting http to https”

  1. Nice post! I love the .isSecure() function a lot - who hasn’t had to deal with this scenario.

    I have been trying to explore the GetPageContext() also. You might want to see what I have so far:

    http://www.bennadel.com/index.cfm?dax=blog:758.view

    I have not gone through the GetRequest() object yet (although I do use the GetRquestURL() string buffer sometimes).

    Anyway, now I want to go and jump into it again :)

    Ben Nadel

  2. Thanks Ben, wow you’ve certainly been exploring getPageContext() hehe!

    Excellent :)

    Michael Sharman

  3. Thank you! this really helped me with a problem

    Nienna

  4. thanked post

    Sohbet

Leave a Reply