This mod displays a flag image and the name of the country based on the IP address a user used to register at your board. The instructions below for viewtopic.php can be easily modified and included basically anywhere on the board where a registered user's id is accessible.
I have created a simple MOD that works great on my board. It only takes like one minute to install and has impressive results. At it's most basic, there are only two PHP files and one template file to edit. There are no database modifications whatsoever. Since installing it I've seen many interesting countries on my board, including China, Australia, Trinidad & Tobago, Thailand, Ukraine, Canada, Japan, the UK, and others! It's nice to see how international your board is!
I am now actively working to turn this into an approved MOD. I'm adding location detection down to a city/region level. This is my first MOD, so tips from seasoned phpBB MOD experts is much appreciated!
TO INSTALL:
First, download this zip file. It includes a directory named flags which has gif icons for the flags (obviously), the free GeoIP.dat data file for October 2009 (it's updated and freely downloadable every month from MaxMind), a php include named geoip.inc which contains the lookup scripts and is also provided by MaxMind, and functions_tulip.php, the TULIP functions.
Upload /flags to your root phpBB 3.x directory. Upload GeoIP.dat, geoip.inc and functions_tulip.php to the phpBB 3.x /includes directory.
Next, open viewtopic.php and find the following line:
Code: Select all
include($phpbb_root_path . 'includes/bbcode.' . $phpEx);
Code: Select all
include($phpbb_root_path . 'includes/functions_tulip.' . $phpEx);
Code: Select all
'POSTER_ID' => $poster_id,
Code: Select all
########## BEGIN TULIP ##########
'POSTER_COUNTRY' => iptocountry($poster_id),
'POSTER_COUNTRY_FULL' => iptocountryname($poster_id),
########## END TULIP ##########
Finally, find the viewtopic_body.html template file inside the directory for whichever style you're using, and add the following line inside the postrow wherever you'd like the flag of the post author to appear:
Code: Select all
<img src="./flags/{postrow.POSTER_COUNTRY}.gif">
Code: Select all
{postrow.POSTER_COUNTRY_FULL}
Code: Select all
<img src="./flags/{postrow.POSTER_COUNTRY}.gif" alt="{postrow.POSTER_COUNTRY_FULL}">
MISCELLANEOUS NOTES:
I've so far found this to work for every country of every author that has yet posted, including Russia and China for spammers I don't know what will happen if the script somehow doesn't recognize an IP address, but I've included an extra flag called UN.gif which is simply the flag of the United Nations, which could be used as a placeholder or default flag. Also, since I created the zip file from the Mac OS X Finder, there is probably some rogue Finder database file in there. Just delete that...
Q&A:
Question: How can I put this on other pages other than viewtopic.php?
Answer: You'll paste in the same code for viewtopic.php mentioned in the instructions, but modify it if necessary to suit the needs of the new use. For example, if you wanted to add it to search results, then you'd want to pull the result row's user_id in search.php, like this:
Code: Select all
'POSTER_COUNTRY' => iptocountry($row['poster_id']),
'POSTER_COUNTRY_FULL' => iptocountryname($row['poster_id']),
Question: How can I make sure my IP address database is up-to-date?
Answer: To updated your database of IP address country codes, simply download a new GeoIP.dat binary database file from MaxMind and upload it to /includes replacing your old copy. MaxMind releases a new GeoIP.dat file on the first of every month.
Question: How can I fix a user's incorrectly reported country?
Answer: If a country is reported incorrectly or not at all, this means the user registered from an unrecognized IP address. To repair this, simply edit the user_ip entry for the affected user in the database, replacing whatever is there with either a corrected IP address, or a "generic" IP address that reflects the user's country. You can find generic IP addresses for every country here. Simply select the desired country and choose an IP address from the list. You can also use this same method to fake your own location, by changing your registered IP address to a different country, although this would be a little shady on your part.