We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 982
    • 1 Posts
    Is there an addon that allows me to detect the location/country of an incoming visitor, and serve up specific site content based on the country?
      • 22303 MODX Staff
      • 10,725 Posts
      Quote from: alexeygu at Jul 07, 2009, 01:49 PM

      Is there an addon that allows me to detect the location/country of an incoming visitor, and serve up specific site content based on the country?
      I don’t believe anything generic for this is available (though would be worth searching the Extras repository), but it should be pretty straightforward to author a plugin which detects this information and modifies the request as needed, depending on your requirements of course.
        • 29774
        • 386 Posts
        I have used Maxmind’s GeoIP web service for this, you need to buy lookup credits but it is a very reliable service suitable for enterprise use. I believe there is also a free version for non-commercial use.

        http://www.maxmind.com/app/web_services

        $query = "http://geoip3.maxmind.com/a?l=" . $license_key . "&i=" . $ipaddress;
        $url = parse_url($query);
        $host = $url["host"];
        $path = $url["path"] . "?" . $url["query"];
        $timeout = 1;
        $fp = fsockopen ($host, 80, $errno, $errstr, $timeout);
        if ($fp) {
          fputs ($fp, "GET $path HTTP/1.0\nHost: " . $host . "\n\n");
          while (!feof($fp)) {
            $buf .= fgets($fp, 128);
          }
          $lines = split("\n", $buf);
          $country = $lines[count($lines)-1];
          fclose($fp);
        } else {
          # enter error handing code here
        }
        echo $country;
        
        
          Snippets: GoogleMap | FileDetails | Related Plugin: SSL
          • 964
          • 11 Posts
          Just for people finding this thread from Google, I’ve written a howto on using MaxMind from within MODx here: http://modxcms.com/forums/index.php?topic=50853.0