1

what is the best method to get visitors country code by IP between the 2 following methods:

  1. Using MaxMind geoip database here.

  2. Run a local whois and grep for the word country like this

    $ip = $_SERVER['REMOTE_ADDR']; // Get users IP
    $country = exec("whois $ip  | grep -i country");
    $country = str_replace('country: ', '', $country);
    

I heard that running a local who is is only work in linux server, is this correct?

Scott Stanchfield
  • 29,742
  • 9
  • 47
  • 65
Wakanina
  • 592
  • 3
  • 6
  • 20
  • Do not use `exec()` from your program to go to the shell to run a whois query and even worse pipe it with grep. Use the appropriate libraries in your programming languages for `whois` or just open a TCP socket on port 43 and read RFC3912 on Whois Protocol Specification. – Patrick Mevzek Jan 03 '18 at 21:57

0 Answers0