[snip] User location flag

    This site uses cookies. By continuing to browse this site, you are agreeing to our Cookie Policy.

    • [snip] User location flag

      I have received many emails about how to do this... it's not really hard and does not need to be scientist... just google for it...

      You can either use this: github.com/maxmind/GeoIP2-php [working on PHP 7.x, which I recommend, saves you time of server configuration and it's ready-to-go]

      or the old version that works in the majority of the VPS OS [I use debian, it's not working on debian 9]: piwik.org/faq/how-to/faq_164/ [which I do not recommend, because can be deprecated anytime]

      -----------------

      If you follow up the GeoIP2 guide through Composer setup [available on the first URL I've added here], you will need to add to General Functions the following:


      PHP Source Code: includes/GeneralFunctions.php

      1. require 'vendor/autoload.php';
      2. use GeoIp2\Database\Reader;
      3. function GeoIsoCode($IP)
      4. {
      5. $reader = new Reader('/home/.../public_html/vendor/maxmind-db/GeoLite2-City.mmdb');
      6. if(isset($IP) && !empty($IP)) {
      7. $IP = $IP;
      8. } else {
      9. $IP = $_SERVER['SERVER_ADDR'];
      10. }
      11. $record = $reader->city($IP);
      12. return $record->country->isoCode;
      13. }
      14. function GeoName($IP)
      15. {
      16. $reader = new Reader('/home/.../public_html/vendor/maxmind-db/GeoLite2-City.mmdb');
      17. if(isset($IP) && !empty($IP)) {
      18. $IP = $IP;
      19. } else {
      20. $IP = $_SERVER['SERVER_ADDR'];
      21. }
      22. $record = $reader->city($IP);
      23. return $record->country->name;
      24. }
      25. function GeoContinent($IP)
      26. {
      27. $reader = new Reader('/home/.../public_html/vendor/maxmind-db/GeoLite2-City.mmdb');
      28. /* Non formated IP's */
      29. if(isset($IP) && !empty($IP)) {
      30. $IP = $IP;
      31. } else {
      32. $IP = $_SERVER['SERVER_ADDR'];
      33. }
      34. $record = $reader->city($IP);
      35. return $record->continent->code;
      36. }
      Display All
      [Warning: since the GeoIP2 uses Geolite database, it is pretty limited on anonymous proxies or null ip's.]


      As you can see it's a very simple snippet.

      GeoIsoCode is needed to obtain user ip flag location
      GeoName obtains country name
      GeoContinent it's useful if you want your users from America pay as USD and Europe pay as EUR.

      There are some examples of application:
      On Statistics Page:

      Source Code: includes/pages/game/ShowStatisticsPage.class.php

      1. foreach ($query as $StatRow)
      2. {
      3. $RangeList[] = array(
      4. 'id' => $StatRow['id'],
      5. 'name' => $StatRow['username'],
      6. 'lang' => GeoIsoCode($StatRow['user_lastip']),
      7. 'langname' => GeoName($StatRow['user_lastip']),
      8. 'userimage' => $StatRow['userimage'],
      9. 'points' => pretty_number($StatRow[$Points]),
      10. 'allyid' => $StatRow['ally_id'],
      11. 'rank' => $StatRow[$Rank],
      12. 'allyname' => $StatRow['ally_tag'],
      13. 'ranking' => $StatRow[$OldRank] - $StatRow[$Rank],
      14. );
      15. }
      Display All
      And a screenshot of how it is shown



      -----------------

      By other alternative if you install old geoip tool, you just need to use the following codes:

      GeoIsoCode > geoip_country_code_by_name
      GeoName > geoip_country_name_by_name
      GeoContinent > geoip_continent_code_by_name

      More can be seen here > php.net/manual/en/book.geoip.php

      The post was edited 5 times, last by Qwa ().

    • Estuve revisando esto a ver si alguien me da una mano, a esto le faltan algunas cosas
      Me devuelve este error

      Source Code

      1. USER ERROR
      2. Message: Class 'GeoIp2/Database/Reader' not found
      3. File: /includes/GeneralFunctions.php
      4. Line: 1008
      5. URL: http://localhost/xnova/game.php?page=statistics
      6. PHP-Version: 7.3.5
      7. PHP-API: apache2handler
      8. 2Moons Version: 2.0.git
      9. Debug Backtrace:
      10. #0 /includes/pages/game/ShowStatisticsPage.class.php(146): GeoIsoCode('::1')
      11. #1 /game.php(58): ShowStatisticsPage->show()
      12. #2 {main}
      Display All


      Ahora incluyo directamente require 'includes/libs/GeoIp2/src/Database/Reader.php';

      Source Code

      1. Parse error: syntax error, unexpected 'DbReader' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST) in D:\xampp miisla\htdocs\xnova\includes\libs\GeoIp2\src\Database\Reader.php on line 47

      Source Code

      1. class Reader implements ProviderInterface
      2. {
      3. private DbReader $dbReader;
      4. private string $dbType;
      5. /**
      6. * @var array<string>
      7. */
      8. private array $locales;
      VERY SAD :/ :/ :/ :/
    • yamilrh wrote:

      Danter14 wrote:

      ¿Seguiste toda la documentación para sus instalaciones con composer?
      Si la leí, pero la verdad no entendí muy bien ;( :(
      basically it's to display the flags of the languages of the players in the statistics you want? because there are plenty of easy ways to do that
    • Danter14 wrote:

      yamilrh wrote:

      Danter14 wrote:

      ¿Seguiste toda la documentación para sus instalaciones con composer?
      Si la leí, pero la verdad no entendí muy bien ;( :(
      basically it's to display the flags of the languages of the players in the statistics you want? because there are plenty of easy ways to do that
      La idea sería que muestre la bandera en la estadísticas pero según su ip y no el del lenguaje que seleccione el usuario
      VERY SAD :/ :/ :/ :/
    • yamilrh wrote:

      La idea sería que muestre la bandera en la estadísticas pero según su ip y no el del lenguaje que seleccione el usuario
      Yes I see what you want to do best and to do it by an api, moreover some api lets you know if it uses a vpn, proxy or tor what you asked me in a message on my wall which allows you therefore to block the players who use them.
    • Danter14 wrote:

      yamilrh wrote:

      La idea sería que muestre la bandera en la estadísticas pero según su ip y no el del lenguaje que seleccione el usuario
      Sí, veo lo que quieres hacer mejor y hacerlo mediante una API, además, una API te permite saber si usa una VPN, un proxy o lo que me pediste en un mensaje en mi muro, lo que te permite bloquear a los jugadores. quienes los usan.
      SI!
      VERY SAD :/ :/ :/ :/