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.
- 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)
- Restart ColdFusion or the JRun instance
- Create a directory for testing in your webroot and copy index.cfm and application.cfc from the zip file above
- 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
- 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