bpurcell.org - Obtaining a users geographical location based on their IP with GeoIP and ColdFusion Example
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Subject Archives
Amazon EC2 (15)
ColdFusionMX (155)
Corvette (3)
Flash Lite (4)
Flash Media Server (5)
Flash Player (3)
Flex (39)
General Web Dev (14)
HDTV (3)
Jboss (1)
Jquery (2)
JRun (59)
Max 2003 (3)
Other (33)
PC Hardware (16)
Software (17)
SpatialKey (7)
Wireless (8)
Working Out (1)

RSS Feed
Feed Listing

Site Contents
My Blog
Wireless & Networking
Hardware & Gadgets
Software Picks
Contact Me

My Articles & Papers
Flex Performance
mm.com Under the Hood
Multiple Instances of CFMX
Multiple Instance Config
NLB with ColdFusion
Clustering CFMX for J2EE
Multi-Tier Hardware LB w CFMX
Cisco CSS & Coldfusion MX
JRun 4 Jini based Clustering
WiFi Growth

2ID Tacweb

Other Hobbys
Body-For-Life Challenge

Personal Projects
Family Pool
Deck Gate


Viewing Individual Entry / Main
September 1, 2008

In my last blog posting I discussed the advantages of using MaxMind GeoIP to obtain a site visitors geographical location based on their IP. In this posting I will show you how to integrate GeoIP into your site using ColdFusion. If you are a ColdFusion developer the most challenging part is getting the java source compiled and into a jar file so that you can leverage the GeoIP Java API in ColdFusion. I have made it easier by taking care of this process

The first thing you will need to do is download the example and jar file. Since this example was written using the Lite version of GeoIP you will need to download the Binary version of the Lite database. After you get it up and running you can download and just replace the .dat file with the full binary version. Go to http://www.maxmind.com/app/geolitecity and look under the section that says "Binary Format", click on the "Download the latest GeoLite City Binary Format" link. After that go ahead and extract the .dat file from the zip.

The zip file that you downloaded above will contain a jar file and two ColdFusion files. Follow along with the steps below and you will be up and running quickly.


  1. Copy geoIP.jar to Jrun4/servers/lib or ColdFusion/runtime/servers/lib (I think that is right for standalone CF it has been a while since I used the standalone version)
  2. Restart ColdFusion or the JRun instance
  3. Create a directory for testing in your webroot and copy index.cfm and application.cfc from the zip file above
  4. Open Application.cfc and modify the entry for REQUEST.GeoIPCityDB to point to the location where you extracted the GeoLiteCity.dat file from above. Make sure you use forward slashes and not backslashes.
  5. You should then be able to invoke index.cfm from the example and start resolving IP's to Geographic locations.

You should be able to take this example code and quickly integrate it into your own site. Overall it is pretty simple, if you are not using an Application.cfc file you will just need to add it to your Application.cfm file. Make sure you add logic so that it only is initialized once. The initial load is a bit expensive but it loads the entire database into memory. It is only about 25MB but it is worth the performance gain you get since you can support hundred-thousands of queries a second. The UDF in the index.cfm file is a little bit bloated but there is some reasoning behind it. When I started using this approach I had already been using IP2Location and had a predefined query structure that I had to adapt to. You can probably simplify the approach for the UDF if you choose to. If there are any other questions feel free to post them or email me.


Just wanted to say thanks for blogging about this. I was able to use your example and get it working for their ORG and ISP data as well.

Firstly, thanks you've single-handedly wiped out my long query log of 6 second IP conversions ;)

Secondly, I'm relatively new in some aspects especially cf functions and despite playing with your code can't get the ISP/Org aspect to work. Any chance you previous poster might have easy instructions handy? Thanks in advance.

thank you for posting this, it worked first time (unusual for me!).

Thanks! Saved me hours and works like a charm on my 64-bit CF9 installation!

TechCrunch is a blog that was founded by Michael Arrington in 2005, which focuses on blogging about breaking news in technology, computers, Internet culture, social media, products, websites and startup companies. The blog has over 4.5 million RSS subscribers and inspired the launch of the TechCrunch Network, which includes a number of related websites like CrunchNotes, MobileCrunch and CrunchGear. TechCrunch was acquired by AOL in September 2010 for US $25 million. Book your blog domain name. When you want to create your own blog and/or photo gallery, the first thing you want to do, is to get a blog domain name. <a href=http://www.blogthishere.com/>Most Popular Blog Here</a> - <a href=http://www.blogthishere.com/>Blog This Here</a>!!!!!!!!

This is still working in Coldfusion 11 on IIS 7.5. I put the jar in /coldfusion11/cfusion/runtime/lib

Page Render Time:218