Standardizing Your URL Data in ColdFusion

We are currently developing coding guidelines and I wanted make URLs were valid and consistently formatted before they were inserted into our SQL tables. Here is a script to standardize the URLs you receive through form data.

This is my first version of a URL cleaning script. It takes a variable that is assumed to be a URL. Then, it takes that string and checks to see if it does not contain http://. The script attempts to load that page and if the header code of the page is 200 OK, which means it was a good load, the variable is trimmed and lower cased. Also, the script checks for three different versions of the URL.



Start: #dirtyURL#
Temp1: #tempURL#
Temp2: #tempURL#
Temp3: #tempURL#
Finish: #cleanURL#

I added the INVALID: prepend to the bad URLs to represent that the URL was not successfully connected. One could run another script on the table to resolve those erroneous URLs.

Like I said, this was my first attempt to standardize the URLs that we receive through form data. This code hasn’t been tested enough to deem it bulletproof. I don’t claim to be a code ninja, so if you know of a better method or would like to tweak this version, please let me know.


RSS feed | Trackback URI

Comments »

No comments yet.

Name (required)
E-mail (required - never shown publicly)
URI
Your Comment (smaller size | larger size)
You may use <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> in your comment.

Trackback responses to this post

ss_blog_claim=85f01294d5e7bb5fef0d6e569c52d7ee