Country Flags by IP Address [Deleted]

Ok well I have a member whose IP shows as Newark, California but the flag shows as Canadian instead of US. Any ideas?
Sure, there could be two possibilities...

1) He's using a proxy (whether intentional or not and almost always happens with mobile connections). This add-on picks up proxies so the IP used will not always match what XenForo shows.

2) The MaxMind database has the location wrong. Which I can do nothing about.

If you want to see which it is, enable logging in the add-on options. After the user is online and showing what you think is an incorrect flag, check the log (data/countryflags/ipaddress.log) for the user ID. The last IP shown on that line is the one used for the flag.
 
Last edited:
@Snog all of a sudden the site crashed and country flags brought everything to a halt. got 5 of this same error:

Code:
Countryflags\Db\Reader\InvalidDatabaseException: Error opening database file (/home/dressedw/public_html/data/countryflags/GeoLite2-Country.mmdb). - library/Snog/CountryFlags/Listener/Includes/Reader.php:248
Generated By: Great White Snark, 15 minutes ago
Stack Trace
#0 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Includes/Reader.php(60): Countryflags\Db\Reader->findMetadataStart('/home/dressedw/...')
#1 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Visitor.php(113): Countryflags\Db\Reader->__construct('/home/dressedw/...')
#2 [internal function]: Snog_CountryFlags_Listener_Visitor::visitor(Object(XenForo_Visitor))
#3 /home/dressedw/public_html/library/XenForo/CodeEvent.php(90): call_user_func_array(Array, Array)
#4 /home/dressedw/public_html/library/XenForo/Visitor.php(477): XenForo_CodeEvent::fire('visitor_setup', Array)
#5 /home/dressedw/public_html/library/XenForo/Session.php(274): XenForo_Visitor::setup(694, Array)
#6 /home/dressedw/public_html/library/XenForo/Controller.php(293): XenForo_Session::startPublicSession(Object(Zend_Controller_Request_Http))
#7 /home/dressedw/public_html/library/XenForo/Controller.php(306): XenForo_Controller->_setupSession('Index')
#8 /home/dressedw/public_html/library/XenForo/FrontController.php(350): XenForo_Controller->preDispatch('Index', 'XenForo_Control...')
#9 /home/dressedw/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#10 /home/dressedw/public_html/index.php(13): XenForo_FrontController->run()
#11 {main}
Request State
array(3) {
  ["url"] => string(51) "http://www.dressedwell.net/forums/mens-clothing.17/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}

2.webp
 
chmod data to 0777 again. Seems to do this every once in a while and running chmod again resolves it. I made a cron to do it daily and never an issue since.
 
@Snog all of a sudden the site crashed and country flags brought everything to a halt. got 5 of this same error:

Code:
Countryflags\Db\Reader\InvalidDatabaseException: Error opening database file (/home/dressedw/public_html/data/countryflags/GeoLite2-Country.mmdb). - library/Snog/CountryFlags/Listener/Includes/Reader.php:248
Generated By: Great White Snark, 15 minutes ago
Stack Trace
#0 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Includes/Reader.php(60): Countryflags\Db\Reader->findMetadataStart('/home/dressedw/...')
#1 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Visitor.php(113): Countryflags\Db\Reader->__construct('/home/dressedw/...')
#2 [internal function]: Snog_CountryFlags_Listener_Visitor::visitor(Object(XenForo_Visitor))
#3 /home/dressedw/public_html/library/XenForo/CodeEvent.php(90): call_user_func_array(Array, Array)
#4 /home/dressedw/public_html/library/XenForo/Visitor.php(477): XenForo_CodeEvent::fire('visitor_setup', Array)
#5 /home/dressedw/public_html/library/XenForo/Session.php(274): XenForo_Visitor::setup(694, Array)
#6 /home/dressedw/public_html/library/XenForo/Controller.php(293): XenForo_Session::startPublicSession(Object(Zend_Controller_Request_Http))
#7 /home/dressedw/public_html/library/XenForo/Controller.php(306): XenForo_Controller->_setupSession('Index')
#8 /home/dressedw/public_html/library/XenForo/FrontController.php(350): XenForo_Controller->preDispatch('Index', 'XenForo_Control...')
#9 /home/dressedw/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#10 /home/dressedw/public_html/index.php(13): XenForo_FrontController->run()
#11 {main}
Request State
array(3) {
  ["url"] => string(51) "http://www.dressedwell.net/forums/mens-clothing.17/"
  ["_GET"] => array(0) {
  }
  ["_POST"] => array(0) {
  }
}
It looks like the GeoLite2-Country.mmdb file is not there for some reason. Try running the 'Update GeoIP Database' cron task to update it and see if there are any errors.
 
chmod data to 0777 again. Seems to do this every once in a while and running chmod again resolves it. I made a cron to do it daily and never an issue since.
If you have problems with the data folder changing permission, it's not coming from this add-on. And I've never experienced the data folder changing permissions on it's own.
 
It looks like the GeoLite2-Country.mmdb file is not there for some reason. Try running the 'Update GeoIP Database' cron task to update it and see if there are any errors.
updated the addon, and checked permission on the data folder. ran the cron and the error popped up immediately

Code:
Countryflags\Db\Reader\InvalidDatabaseException: Error opening database file (/home/dressedw/public_html/data/countryflags/GeoLite2-Country.mmdb). - library/Snog/CountryFlags/Listener/Includes/Reader.php:248
Generated By: viaattovannucci, A moment ago
Stack Trace
#0 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Includes/Reader.php(60): Countryflags\Db\Reader->findMetadataStart('/home/dressedw/...')
#1 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Visitor.php(113): Countryflags\Db\Reader->__construct('/home/dressedw/...')
#2 [internal function]: Snog_CountryFlags_Listener_Visitor::visitor(Object(XenForo_Visitor))
#3 /home/dressedw/public_html/library/XenForo/CodeEvent.php(90): call_user_func_array(Array, Array)
#4 /home/dressedw/public_html/library/XenForo/Visitor.php(477): XenForo_CodeEvent::fire('visitor_setup', Array)
#5 /home/dressedw/public_html/library/XenForo/Session.php(274): XenForo_Visitor::setup(738, Array)
#6 /home/dressedw/public_html/library/XenForo/Controller.php(293): XenForo_Session::startPublicSession(Object(Zend_Controller_Request_Http))
#7 /home/dressedw/public_html/library/XenForo/Controller.php(306): XenForo_Controller->_setupSession('Index')
#8 /home/dressedw/public_html/library/XenForo/FrontController.php(350): XenForo_Controller->preDispatch('Index', 'LiveUpdate_Cont...')
#9 /home/dressedw/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#10 /home/dressedw/public_html/index.php(13): XenForo_FrontController->run()
#11 {main}
Request State
array(3) {
  ["url"] => string(47) "http://www.dressedwell.net/index.php?liveupdate"
  ["_GET"] => array(1) {
    ["liveupdate"] => string(0) ""
  }
  ["_POST"] => array(4) {
    ["_xfRequestUri"] => string(61) "/threads/passaggio-cravatte-the-scandal-continues.814/page-54"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
  }
}
 
updated the addon, and checked permission on the data folder. ran the cron and the error popped up immediately

Code:
Countryflags\Db\Reader\InvalidDatabaseException: Error opening database file (/home/dressedw/public_html/data/countryflags/GeoLite2-Country.mmdb). - library/Snog/CountryFlags/Listener/Includes/Reader.php:248
Generated By: viaattovannucci, A moment ago
Stack Trace
#0 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Includes/Reader.php(60): Countryflags\Db\Reader->findMetadataStart('/home/dressedw/...')
#1 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Visitor.php(113): Countryflags\Db\Reader->__construct('/home/dressedw/...')
#2 [internal function]: Snog_CountryFlags_Listener_Visitor::visitor(Object(XenForo_Visitor))
#3 /home/dressedw/public_html/library/XenForo/CodeEvent.php(90): call_user_func_array(Array, Array)
#4 /home/dressedw/public_html/library/XenForo/Visitor.php(477): XenForo_CodeEvent::fire('visitor_setup', Array)
#5 /home/dressedw/public_html/library/XenForo/Session.php(274): XenForo_Visitor::setup(738, Array)
#6 /home/dressedw/public_html/library/XenForo/Controller.php(293): XenForo_Session::startPublicSession(Object(Zend_Controller_Request_Http))
#7 /home/dressedw/public_html/library/XenForo/Controller.php(306): XenForo_Controller->_setupSession('Index')
#8 /home/dressedw/public_html/library/XenForo/FrontController.php(350): XenForo_Controller->preDispatch('Index', 'LiveUpdate_Cont...')
#9 /home/dressedw/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#10 /home/dressedw/public_html/index.php(13): XenForo_FrontController->run()
#11 {main}
Request State
array(3) {
  ["url"] => string(47) "http://www.dressedwell.net/index.php?liveupdate"
  ["_GET"] => array(1) {
    ["liveupdate"] => string(0) ""
  }
  ["_POST"] => array(4) {
    ["_xfRequestUri"] => string(61) "/threads/passaggio-cravatte-the-scandal-continues.814/page-54"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
  }
}
After you updated the add-on and ran the cron task, are there any other errors in the admin error log?

EDIT: Clear the error log and see if the error continues. The file does exist on your server and is valid. It MAY have been missing or being written to when that user's country was checked and happened while the file was being downloaded/extracted.
 
Last edited:
After you updated the add-on and ran the cron task, are there any other errors in the admin error log?
nope

EDIT: Clear the error log and see if the error continues. The file does exist on your server and is valid. It MAY have been missing or being written to when that user's country was checked and happened while the file was being downloaded/extracted.
it continued

Code:
Countryflags\Db\Reader\InvalidDatabaseException: Error opening database file (/home/dressedw/public_html/data/countryflags/GeoLite2-Country.mmdb). - library/Snog/CountryFlags/Listener/Includes/Reader.php:248
Generated By: doghouse, Today at 2:23 PM
Stack Trace
#0 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Includes/Reader.php(60): Countryflags\Db\Reader->findMetadataStart('/home/dressedw/...')
#1 /home/dressedw/public_html/library/Snog/CountryFlags/Listener/Visitor.php(113): Countryflags\Db\Reader->__construct('/home/dressedw/...')
#2 [internal function]: Snog_CountryFlags_Listener_Visitor::visitor(Object(XenForo_Visitor))
#3 /home/dressedw/public_html/library/XenForo/CodeEvent.php(90): call_user_func_array(Array, Array)
#4 /home/dressedw/public_html/library/XenForo/Visitor.php(477): XenForo_CodeEvent::fire('visitor_setup', Array)
#5 /home/dressedw/public_html/library/XenForo/Session.php(274): XenForo_Visitor::setup(174, Array)
#6 /home/dressedw/public_html/library/XenForo/Controller.php(293): XenForo_Session::startPublicSession(Object(Zend_Controller_Request_Http))
#7 /home/dressedw/public_html/library/XenForo/Controller.php(306): XenForo_Controller->_setupSession('Refresh')
#8 /home/dressedw/public_html/library/XenForo/FrontController.php(350): XenForo_Controller->preDispatch('Refresh', 'Siropu_Chat_Con...')
#9 /home/dressedw/public_html/library/XenForo/FrontController.php(134): XenForo_FrontController->dispatch(Object(XenForo_RouteMatch))
#10 /home/dressedw/public_html/index.php(13): XenForo_FrontController->run()
#11 {main}
Request State
array(3) {
  ["url"] => string(49) "http://www.dressedwell.net/index.php?chat/refresh"
  ["_GET"] => array(1) {
    ["chat/refresh"] => string(0) ""
  }
  ["_POST"] => array(15) {
    ["room_id"] => string(1) "0"
    ["user_rooms"] => array(1) {
      [0] => string(5) "22139"
    }
    ["last_id"] => string(5) "22139"
    ["activity_last_update"] => string(10) "1471285325"
    ["users_last_update"] => string(10) "1471285354"
    ["inverse"] => string(1) "0"
    ["hide_bot"] => string(1) "0"
    ["no_users"] => string(1) "0"
    ["show_ignored"] => string(1) "0"
    ["all_pages"] => string(1) "0"
    ["loading"] => string(1) "0"
    ["_xfRequestUri"] => string(8) "/forums/"
    ["_xfNoRedirect"] => string(1) "1"
    ["_xfToken"] => string(8) "********"
    ["_xfResponseType"] => string(4) "json"
  }
}

i have to keep the addon off otherwise i'm not able to load the site and the server CPU jumps to almost 100%.
 
i have to keep the addon off otherwise i'm not able to load the site and the server CPU jumps to almost 100%.
Ok, it's question and answer time then. ;)

1) Is this a new install of the add-on?
1a) If NO, what has changed on your server recently? (new add-on, server changes)
2) What version of XenForo are you running?
4) What version of PHP are you running?
5) What version of MySql are you running?
6) What server software are you running (linux, windows, etc)?
 
Last edited:
The old files (before your recent update) might have been cached if he used opcache btw. Just leaving this here, in case you guys miss that part like I always did with whichever add-on (even mine).
 
The old files (before your recent update) might have been cached if he used opcache btw. Just leaving this here, in case you guys miss that part like I always did with whichever add-on (even mine).
I don't think that's the case here since looking back through the thread this isn't a new install. The add-on just doesn't stop working all of a sudden on it's own.

Something changed on his server or site to cause the problem.
 
I'm pretty sure you said that there was a check in the script to check whether the file exists or not. So if it doesn't, it won't log that error. And I kinda assumed that you added the check on your recent update. But after seeing your edit, well, I guess it wasn't opcache then, lmao
 
I'm pretty sure you said that there was a check in the script to check whether the file exists or not. So if it doesn't, it won't log that error. And I kinda assumed that you added the check on your recent update. But after seeing your edit, well, I guess it wasn't opcache then, lmao
Yeah, I reread the error a hundred times and had to edit my reply a couple of times. The error that's coming up isn't that the file doesn't exist, it's an error reading the file. But the file is valid and readable when I grab it from his site and use it on my development server.

The update only added errors in the cron task that takes place once a month (or manually run). It didn't touch the code for getting the user's country.
 
Last edited:
I'm getting lots of users in Florida & California showing Canadian flag but their IP's check out as USA. What do I need to do?
 
I'm getting lots of users in Florida & California showing Canadian flag but their IP's check out as USA. What do I need to do?
This can happen for one of two reasons:

1) The user is using a proxy. This add-on picks up proxies and they can be different than the IP shown by XenForo.
2) The Maxmind database has the wrong information.

There's nothing you can do about either one. If you want to confirm the IP being used by the add-on, enable 'Log IP Addresses' in the add-on options and check the last IP shown on the line for the user or send me the log via PC and I can check it.

NOTE: Many Canadian users are in Florida and California using their Canadian provider.
 
These are long term members of fixed abode & the IP check shows USA. I'll look at the logs.

Many thanks
 
Top Bottom