This plugin might exist allready, but I couldn’t find it using google, so here it is
The plugin gives you four functions you can use in your blog:
get_geoip_country_code and get_geoip_country_name returns the the visitors country code / name
the_geoip_country_code and the_geoip_country_name echos the the visitors country code / name
INSTALLATION:
1) Extract the plugin into your WordPress plugins directory.
2) Download the free GeoIP country database from MaxMind , and extract it into your plugins/GeoIP directory
3) Optional, If you need country flags, you’ll find them here: http://www.maxmind.com/download/geoip/database/flag.zip
4) Activate it on the Plugins tab of the WordPress admin console.
SAMPLE USE:
<img src="/flag/<?php echo
strtolower(get_geoip_country_code())?>.gif" alt="<?php
the_geoip_country_name()?>" />
NOTE, If you have full access to your server and it’s running Apache, you should take a look at the mod_geoip
4 Comments
Note that there are some errors in your code, as noted in the wordpress support forum (http://wordpress.org/support/topic/10274#post-233538). You cannot pass variables as default argument values, as stated in http://www.php.net/manual/en/functions.arguments.php.
In line 53:
function get_geoip_country_code($ip = $_SERVER["REMOTE_ADDR"]) { should be changed to something like:
function get_geoip_country_code($ip = NULL) {
if (is_null($ip)) {
$ip = $_SERVER["REMOTE_ADDR"];
}
Also note that there is a missing closing parenthesis in all your realpath calls.
Hope that helps.
Roberto Zoia
roberto dot zoia [at] gmail dot com
Also, for a WP2.0.2 I had to change line 51 to read
include(“GeoIP/geoip.inc”);
instead of the original ‘wp-content/plugins/GeoIP/geoip.inc’ path.
Cheers for the plugin!
I’ve seen this such plugin here
http://frenchfragfactory.net/ozh/archives/2004/08/27/ip-to-nation-plugin/
emptyspace, not sure what you’re trying to say.
Mine is not a copy of ip-to-nation, mine is a php port from my VBscript GeoIP Class that I wrote in 2002.
Also, mine is using the MaxMind database i.e. you don’t have to add/update geoip data to your mysql database
Post a Comment