PHP Code Detect Country - Php

How do you detect country using PHP code?

Snippet Code

Rate this page :
  [ 0 votes]

The below PHP code is used to detect your website visitors country. Here, you have to download "simple_html_dom.php" file and include into it. You can easily find the country name using visitors IP address.

<?php function get_country($ipaddr) { include_once('./simple_html_dom.php'); $urll="$ipaddr"; $html = file_get_html("$urll"); $whohtml=array(); $w=0; foreach($html->find('table tr td') as $element) { $whohtml[$w]=$element->plaintext; $w++; } $country=str_replace("Country :","","$whohtml[0]"); $country=str_replace("()","","$country"); return $country; } $ipaddr=""; //$_SERVER['REMOTE_ADDR']; echo get_country($ipaddr); ?>


Ask Questions

Ask Question