We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 14214
    • 299 Posts
    So a project I am working on requires us to display pricing for site visitors. Problem is our pricing varies by country due to our costs of doing business there. We have had issues with a customer from say Japan seeing Canadian pricing and thinking they are getting ripped off.

    Has anyone used geo data from the browser or IP to customize the display of content to the visitor? Is there an Extra for this?

    This question has been answered by jisaac. See the first response.

    [ed. note: jisaac last edited this post 12 years, 2 months ago.]
      • 14214
      • 299 Posts
      **bump**
        • 40045
        • 534 Posts
        No extra that I know of, this is quite custom stuff here =)...and IP-Geofencing is not 100% reliable. I'd say you need to include something like http://freegeoip.net/ in combination with cURL from your site to do stuff like: freegeoip.net/{format}/{ip_or_hostname} (but API usage is limited to 10,000 queries per hour!). There are also other GeoIP resources (local database, https://github.com/maxmind/GeoIP2-php).
        • discuss.answer
          • 14214
          • 299 Posts
          Thanks exside.

          Here is what I've done:

          I need for my US visitors to display a link to shopping online (as I only sell online to domestic US customers). For International visitors I wish to provide a button pointing them to my locate a distributor page.

          I DL'd the MaxMind database here: http://dev.maxmind.com/geoip/legacy/geolite/

          There are two snippets I created. Then I created a geoLocation snippet:
          <?php
          include("/home/user-name/public_html/geo/geoipcity.inc");
          include("/home/user-name/public_html/geo/geoipregionvars.php");
          $gi = geoip_open("/home/user-name/public_html/geo/GeoLiteCity.dat", GEOIP_STANDARD);
          
          $record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
          if($record->country_code == "US"){
          echo '[[$displayUSChunk]]';
          }
          else{
          echo '[[$displayINTLChunk]]';
          }
          geoip_close($gi);


          For me it is not critical to be 100% accurate on the locations but it does become beneficial to sort the visitors.
            • 14214
            • 299 Posts
            Quote from: jisaac at Jul 31, 2014, 07:17 AM
            Thanks exside.

            <!--?php
            include("/home/user-name/public_html/geo/geoipcity.inc");
            include("/home/user-name/public_html/geo/geoipregionvars.php");
            $gi = geoip_open("/home/user-name/public_html/geo/GeoLiteCity.dat", GEOIP_STANDARD);
            
            $record = geoip_record_by_addr($gi, $_SERVER['REMOTE_ADDR']);
            if($record--->country_code == "US"){
            echo '[[$displayUSChunk]]';
            }
            else{
            echo '[[$displayINTLChunk]]';
            }
            geoip_close($gi);


            Need some help modifying this for use with Cloudflare CDN.

            This is their request location code:
            $country_code = $_SERVER["HTTP_CF_IPCOUNTRY"];


            Need to replace my current lookup function, anyone who can assist is greatly appreciated.
              • 14214
              • 299 Posts
              Solved using:

              <?php
              $tplDomesticResponse = $modx->getOption('tplDomesticResponse',
               $scriptProperties, 'ACCESS');
              $tplIntlResponse = $modx->getOption('tplIntlResponse', $scriptProperties,
               'NOACCESS');
              
              $country_code = $_SERVER["HTTP_CF_IPCOUNTRY"]; 
              if ($country_code=="US") {
                  $output = $modx->getChunk($tplDomesticResponse);
              } 
              else {
                  $output = $modx->getChunk($tplIntlResponse);
              }
              return $output;