Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Geoip and metamod processing sequence
Geoip and metamod processing sequence
Geoip and metamod processing sequence
Does the metamod module do a geoip lookup if it's turned on in the module settings, but no geoip variables are called?
I want to do lookups only once, and store the result in a cookie. It only does the lookup if the cookie exists.
At the moment I have this coded and working in a single metamod, but I'm wondering if the module does the lookup even if no geoip variables are actually referenced? Or should I nest it another metamod?
thanks!
david
Re: Geoip and metamod processing sequence
Hi David,
if you have the GeoIP selector turned on, then it will always do a lookup. That's so that the $fromCountryId and $fromCountryName variables will be populated before it gets to the PHP section.
If you want to, you can bypass the standard lookup, and do it yourself if you want to. I think this will work:
$ip = modMetaModHelper::getUserIP();
$include_file = JPATH_SITE . DS . 'geoip' . DS . 'GeoIP.dat'; // adjust if necessary
if (!function_exists("geoip_open")) {
include_once(JPATH_SITE . DS . "modules" . DS . "mod_metamod" . DS . "mod_metamod" . DS . "geoip-php4" . DS . 'geoip.inc');
}
// open the data file
$gi = geoip_open( $include_file, GEOIP_STANDARD );
$fromCountryId = utf8_encode(geoip_country_code_by_addr($gi, $ip));
geoip_close( $gi );
Naturally you'll need to do other stuff with that to insert it into a cookie, and to check for the cookie before you do the code above.
You mentioned nesting in another MetaMod. Yes, you could do that too, but I guess that you are wanting to cut down on the lookup for the sake of speed and efficiency, so I think that the code above will be best. Just down't forget to turn the GeoIP selector "off" so that it doesn't calculate it automatically first.
Hope that helps,
Stephen
Re: Geoip and metamod processing sequence
$ip = modMetaModHelper::getUserIP();
$include_file = JPATH_SITE . DS . 'geoip' . DS . 'GeoLiteCity.dat'; // adjust if necessary
if (!function_exists("geoip_open")) {
include_once(JPATH_SITE . DS . "modules" . DS . "mod_metamod" . DS . "mod_metamod" . DS . "geoip-php4" . DS . 'geoipcity.inc');
}
// open the data file
$gi = geoip_open( $include_file, GEOIP_STANDARD );
$geoip = geoip_record_by_addr($gi, $ip);
modMetaModHelper::convertToUtf8($geoip);
geoip_close( $gi );
// now you can use:
// $geoip->country_name
// $geoip->country_code
// $geoip->country_code3
// $geoip->region
// $geoip->city
// $geoip->postal_code
// $geoip->latitude
// $geoip->longitude
// $geoip->dma_code
// $geoip->area_code
- Index
- » MetaMod Pro
- » MetaMod Pro General Support
- » Geoip and metamod processing sequence
Board Info
- Board Stats:
- Total Topics:
- 1689
- Total Polls:
- 6
- Total Posts:
- 5943
- Posts this week:
- 2
- User Info:
- Total Users:
- 7642
- Newest User:
- mary26
- Members Online:
- 0
- Guests Online:
- 203
- Online:
- There are no members online
Forum Legend:
Topic
New
Locked
Sticky
Active
New/Active
New/Locked
New Sticky
Locked/Active
Active/Sticky
Sticky/Locked
Sticky/Active/Locked