The Dev Pages

A knowledge base for simple (and beyond) web applications development

Archive for the ‘Random Thoughts’ Category




Use CGI.HTTP_HOST

Issue: mydomain.com gets load-balanced and uses multiple servers. CGI.SERVER_NAME will not return ‘mydomain’ but will return ’sever1′ or ’server2′ etc.

I want to check the request URL, and if it does not include www, re-locate to www.mydomain/pagerequested?event=eventrequested


<cfset secureurl = xmlParse(expandPath("/mydevenvironment/settings.xml")).
settings.secureHost.xmlText />
<cfloop collection="#CGI#" item="field">
<cfoutput>#field#: #CGI[field]# <BR></cfoutput>
</cfloop>
<cfif NOT REFind("www\.", CGI.HTTP_HOST)>

<cfif CGI.HTTPS EQ "on">
<cfset theURLBase = secureurl />
<cfelse>
<cfset theURLBase = REREplace(secureurl,"https:","http:")/>
</cfif>
<cfoutput>#theURLBase#</cfoutput>
<cflocation url='#theURLBase##CGI.SCRIPT_NAME#?#CGI.QUERY_STRING#'addtoken="false">
</cfif>

Cart/Session Data vs Form data


Posted on May - 23 - 2008



So I was making a form that was originally one page, to submit and order.

It got more complex when I learned I should probably get the tax/subtotal/verification from our order processor before submitting the final order.

So now I had a 2 part form. Part one: Enter line items Process part one: Calculate subtotal/tax and list info for verification Part2:Verify info and submit for final order processing.

Still, just 2 steps, not a very big deal, right? I didn’t want to worry about the session, a cart, etc. I ended up passing the info from step 1 (lineitems) and cloning it on step two into hidden form values, so these lineItems would be available when step 2 was processed.

The kicker for me to switch to use a cart was that in order for me to calculate the price from the lineItems, I needed the price and the totals to not be form data that could be manipulated by the user. Instead of adding hidden price fields on the form, and worry about that specific security issue of modifying form data pricing, I just decided to keep track of the pricing in the session, on the cart, which also reduced my amount of form value overhead, bu mades things a little more complex.

Oh well, I needed to get familiar with our shopping cart object anyways.