How can I get user's country flag on my site

前端 未结 5 1847
野性不改
野性不改 2021-02-10 13:04

I wanna display user\'s/visitor\'s country flag on my site.

I am using different technologies like php,jsp and simple html. So I want a code which by placing on my site,

5条回答
  •  梦毁少年i
    2021-02-10 13:37

    1. Get the IP of visitor.

       if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
          $ip = $_SERVER['HTTP_CLIENT_IP'];
      } elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
          $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
      } else {
          $ip = $_SERVER['REMOTE_ADDR'];
      }
      
    2. Use ip2location to find the country of the user.

      http://dev.maxmind.com/geoip/legacy/geolite/

    3. Compare the resulting country to a list of images and display the matching image. I suggest using a database to store the country name and the path to the associated image.

提交回复
热议问题