This one bugged me today, but I finally got it working after pulling code from all over the web. Seems simple, but there are so many un-finished tutorials on finding country codes (including uploading a database, which is complete overkill IMO). Anyway, I've written a post here so it's all in one place. Let me know if this is useful to you. http://www.iamseo.org/how-to/capture-user-ip-location-and-referring-url/