Page 2 of 2

Re: GeoIP - Redirecting user to a specific page based on the

Posted: Fri Mar 18, 2011 5:54 pm
by mr.bacan
spcherub wrote:This will not work if the UDT cannot be processed inside the template.
Well, it seems that UDT can be processed inside the template, because it's working perfect. Thank you a lot.

One other question. Right now it shows a 2 letter country code, what should I do in order to convert those into a full name, for example "US" = United States.

Thanks again for your help.

Re: GeoIP - Redirecting user to a specific page based on the

Posted: Fri Mar 18, 2011 6:03 pm
by spcherub
@mr.bacan - thanks for confirming that the UDT works inside the template - that is good to know for future use.

Regarding your question - try this:
Change the UDT to this -

Code: Select all

global $gCms;
$smarty = &$gCms->GetSmarty();
$myarray = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.getenv("REMOTE_ADDR")));
$smarty->assign('country_code', $myarray['geoplugin_countryCode']);
$smarty->assign('country_name', $myarray['geoplugin_countryName']);
As per the documentation at http://www.geoplugin.com/webservices/php, the country name will now be in the $country_name smarty variable.

Let me know how this works.

-S

Re: GeoIP - Redirecting user to a specific page based on the

Posted: Fri Mar 18, 2011 6:13 pm
by mr.bacan
@spcherub

You are GENIUS!
It's working great, showing the complete country name.

Once again, thanks for your extremely quick help.

Re: GeoIP - Redirecting user to a specific page based on the

Posted: Wed Aug 31, 2011 11:42 am
by spcherub
@debim5767 - This is a forum for CMS Made Simple and not for Joomla, so you may not find much here for your specific CMS. Having said that, it is fairly easy to adapt the code included earlier into something that can be used for any PHP-based system. Something like this could work as long as you have it on the very top of the script - of course you'll have to adapt it for the specifics of Joomla.

Code: Select all

$myarray = unserialize(file_get_contents('http://www.geoplugin.net/php.gp?ip='.getenv("REMOTE_ADDR")));

switch($myarray['geoplugin_countryCode']) {
case 'IN': header( 'Location: http://www.yoursite.com/index_india.html' )
break;

case 'AU': header( 'Location: http://www.yoursite.com/index_australia.html' )
break;

...so on a so forth for other countries...
}
As mentioned earlier the list of country codes is available at http://www.theodora.com/country_digraphs.html

Hope this helps.

-S