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="http://whoisthisip.com/$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="122.178.161.204"; //$_SERVER['REMOTE_ADDR']; echo get_country($ipaddr); ?>

Tags


Ask Questions

Ask Question