System - Geo IP
- Download System - Geo IP from the RicheyWeb download page.
- This page will remain unlinked, as the link may change in the future. Visit http://www.richeyweb.com and use the search feature - search for "System - Geo IP".
- In Joomla /administrator, go to the "Extensions" menu, the "Manage" sub-menu, and the "Install" sub-menu.
- Select the "Upload Package File" tab
- Press the "Choose File" button to browse your system and locate the plugin file you downloaded
- Press the "Upload & Install" button
At this point, the extension is installed but not enabled. You can find the plugin by going to the Extensions menu and selecting "Plugins". When in the plugin manager, search for "System - Geo IP".
Developers wishing to utilize this plugin in their own extensions:
The plugin itself listens to no system events. It is implemented as a system plugin so it can run as early as possible to automatically retrieve the IP info for the user browsing the site. That information is cached in memory so it can be retrieved by any extension with little overhead.
As a result of being initiated so early in the Joomla page lifecycle, the helper instance can be accessed with little code/effort in any extension that needs to access it. Getting a copy of the instance is simple:
$geoiphelper = GeoIPHelper::getInstance();
Once you have an instance, there are 3 methods you can call. If an IP has been looked up previously (and cached), the result will be retrieved from cache. If you're looking up a lot of IP addresses (hundreds or thousands), you should probably not cache the results as this will begin to consume a significant amount of memory.
Returns the 2 character country code for the requested IP address. Example: US
Returns the (usually) 3 character country abbreviation for the requested IP address. Example: USA
Returns the full name of the country for the requested IP address. Example: United States
A complete caching example
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR'); $geoiphelper = GeoIPHelper::getInstance(); $countryname = $geoiphelper->lookupName($ip);
A complete non-caching example
$ip = filter_input(INPUT_SERVER, 'REMOTE_ADDR'); $geoiphelper = GeoIPHelper::getInstance(); $countryname = $geoiphelper->lookupName($ip,false);
The update is retrieved from http://chir.ag/projects/geoiploc/ by RicheyWeb servers every night at midnight. To ensure the safety of the contents, the archive is extracted and the contents examined to ensure there is only one file in the archive and that file is a PHP file. It is then re-packaged in a zip and placed within my site structure for distribution via my CDN. For best results with your cron jobs, set the time to after midnight UTC - give me 5 minutes after midnight to be certain that my processes have completed.
Go to the forums - I'll be happy to help.