Welcome to the MetaMod and Chameleon Support Forums.

Before posting, please check out the FAQs.

helpme

 

Need extra help with your Joomla site? Consider paid Joomla support by the developer of Chameleon and MetaMod.

 

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

david steadson
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Geoip and metamod processing sequence

Thanks Stephen. What would the could be to include CityLite lookups?

david steadson
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

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

Stephen Brandon
MetaMod / Chameleon developer
If you use MetaMod or Chameleon, please post a rating and a review at the Joomla! Extensions Directory: Chameleon | MetaMod

metamodguy
useravatar
Offline
3328 Posts
User info in posts
Administrator has disabled public posting

Re: Geoip and metamod processing sequence

thanks, works great.

david steadson
Beginner Modder
ranks
useravatar
Offline
5 Posts
Administrator has disabled public posting

Board Info

Board Stats:
 
Total Topics:
1679
Total Polls:
6
Total Posts:
5933
Posts this week:
4
User Info:
 
Total Users:
4384
Newest User:
rash39381
Members Online:
0
Guests Online:
190

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