Monthly Archives: August 2008

Kill Session When User Closes the Browser

In an extranet or intranet website you may want to limit the user’s access to a unique machine at at time.
One way to do that is to have a table with the logged users and check the new user against that table and block his access if there is already one instance of that user logged in.
But, what if the user shutdown the browser, or the computer, without logging out of the system ? In that case, he will never be able to loggin again, unless he calls support to clear his record or waits until the session time out.

I found a way to clear the user records in case of window or browser closing, but your content should be inside an iFrame, to keep the main window open and the user logged in. When the user changes pages or close the browser, the event “onBeforeUnload” will call a javascript function that calls a CF template to kill the user session. In that template that kills the session, you may write your code to update the user table.

Download the sample code here.

Read More…

RegEx Tester

Pardon me if you guys already have seen that, but I’m posting everything I find interesting to the community.
For those who don’t know yet this site, Grant Skinner made available to us a nice tool for testing a regular expression: http://gskinner.com/RegExr/

SQL Injection Hack using CAST from 1.verynx.cn

I found some interesting articles about this hacker attack using SQL injection and I’m aggregating them here. I got this custom tag from “Por que CF” (Why CF) written by Pedro Claudio (CF-Brasil), and here is its usage:
<cf_DisableSQLInjection> Block and log the results
<cf_DisableSQLInjection mailto=“e-mail,e-mail,e-mail,e-mail”>Block, log and send e-mail
<cf_DisableSQLInjection mailto=“e-mail,e-mail,e-mail,e-mail” mailfrom=“mail”>Block, log and send e-mail
<cf_DisableSQLInjection mailto=“e-mail” mailfrom=“mail” title=“Erro 404″ >Block, log, and send email with a title
<cf_DisableSQLInjection mailto=“e-mail” mailfrom=“mail” title=“Erro 404″ message=<h3>Erro 404 – page not found</h3> >Block, log, send a message with title and HTML message

Download the custom tag here.

There is another excellent article with examples by Devit!.

Generate IDs for Customers, Vendors, Products, etc.

I used to do customization for a great accounting software that sold more than 150 thousand copies in the United States. In their manual, they suggested to create IDs for your customers, vendors or products using the following criteria: 3 letters and 2 numbers. You should take the first letter of each word of the name to encode, and add a sequential 2-digit number according to the availability in your database. I never ran out of IDs, no duplicates, no conflicts using that criteria.

The software was written in FoxPro, and we had to create manually the IDs, which was a pain in the neck and time consuming. So I wrote a huge code to generate the IDs automatically when entering a new record. In 2000 I was far from Foxpro and already a ColdFusion developer for 3 years, so I decided to create a custom tag using the same principles of my old code. Later I wrote a component which I have been using in the company I work for since 2002.

You may download the component, instructions and a test template here.

Read More…

ColdFusion Job Opening in Tampa

A friend of mine from K-Force staffing agency asked me if I knew someone for this opening, so I’m posting it here:

Need to be a hands on developer with Coldfusion with strong application development skills. Will be leading a team of 5-6 people and want the person to have had past management responsibilities. Will be leading the operations team that will be handling smaller, quicker projects not related to the Recruitmax Enhancement work. Will be responsible for handling the tactical type of projects.

Read More…

Simple Hit Counter With Images Display

I just converted an old custom tag I had created for hit counters into a function which can be used in a component. It increments a counter in a database table and returns the current hit number in a numeric and a graphic formats. It does not count unique visitors, it is very simple and you can count several pages and/or domains. After calling the function, you decide if you want to display the graphic result or just use the numeric value for some calculation.

You may download the component, instructions, images and test template [here].

Read More…

Regular Expression to Filter Digits and Commas (European values)

I found this code some time ago in some blog, it is not mine, and I do not recall the author’s name, so I beg his/her pardon for not giving the credits, but I think this very interesting and simple for my friends from Brazil and Europe where they use commas instead of dots for decimal positioning.
This code will change a string like 1.234,56 into American format 1,234.56, very useful for converting an input value before inserting it into a database table.

Read More…

Simple Translator Utility Using Yahoo's Babelfish

I read an article from CF-Brasil mail list where the author (Fabio Cezar Gouveia) posted a small utility which sends a text to Yahoo’s Babelfish site and retrieves the translation using CFHTTP tag. The author asked if someone could improve the code and make it public, so I’m doing it. I made it a function and placed in a template with a form that calls itself. You may download the code here.

Read More…

Populating a Multi-Lingual Site from a Database

Professional web sites do not rely on Google Translator or other automated tools. Although we can have an idea of the translated subject, not always the translation is 100% accurate and could cause problems for the site owner. Nothing wrong with the client submitting the page to the translation tool, since it is his option and decision to do that, but if you wish to construct a professional multi-lingual web site, I recommend that you spend the time and resources translating all the content by using a human translator.

I have a simple and fast method of building a multi-lingual web site. First you should start by creating a table with all the languages you will use on the site. Think of that as a spreadsheet where each line will be a field or text to be displayed on your pages, and each column will be the selected language. Translate all your content and feed that table. Then, on your Application.cfm or Application.cfc file, load the entire table to the application scope. In the company I work, we load it to the server scope, since we have several multi-lingual web sites, and that saves memory in our case, since we are not loading the same table for each site.
Once the application (or server, in my case) started, you will have the entire dictionary available for all pages. For each page you then call a function to load only the labels or content you need for that page into a structure (I call it: lang), and then you output it on your page as for example: #lang.save# which would display the word “save” in English or “sauvegarder” in French.
You may download my sample application here, which includes the component, spreadsheet, table script, application.cfm and sample code.

Read More…