Using the GEOIP plugin in other plugins

2 years 8 months ago #78942

Simon Logan's Avatar Simon Logan

Hi Peter

I've inherited a site from another developer and they have written a custom plugin which redirects traffic based on IP address (but only for two locations - France and the Middle East). After upgrading the server to PHP5.6 the plugin generated errors and from my research it looks like it's because the plugin relied on the PECL extension ( ) which is no longer packaged with PHP. The error being:

Fatal error: Call to undefined function geoip_country_code_by_name() in /path/to/plugins/system/ipredirect/ipredirect.php on line 52

My question is, am I able to use/adapt this existing plugin to use the info from the GEOIP plugin? It looks to me like the plugin just requests a country code for the visitor's IP address then checks if it equals FR or ME (with ME being an array of multiple countries which are defined in the plugin) then references the page set in the plugin's parameters for each to execute the redirect.

2 years 8 months ago #78949

Peter van Westen's Avatar Peter van Westen Admin

Here is an example of how you can use it.

2 years 8 months ago #78952

Simon Logan's Avatar Simon Logan

Great, thanks Peter, will give that go.