{"id":1160,"date":"2022-07-17T10:58:16","date_gmt":"2022-07-17T05:28:16","guid":{"rendered":"https:\/\/lookouthost.com\/?p=1160"},"modified":"2022-07-17T10:58:42","modified_gmt":"2022-07-17T05:28:42","slug":"how-to-get-visitors-country-by-ip-in-php","status":"publish","type":"post","link":"https:\/\/lookouthost.com\/blog\/how-to-get-visitors-country-by-ip-in-php\/","title":{"rendered":"How To Get Visitor&#8217;s Country by IP in PHP"},"content":{"rendered":"<p>This example shows how to get a visitor&#8217;s country using their ip in PHP language. This script doesn&#8217;t show how to get ip which we will discuss in another article.<\/p><pre class=\"wp-block-code\"><code>&lt;?php\r\n\/\/ PHP code to obtain country, city,\r\n\/\/ continent, etc using IP Address\r\n\r\n$ip = '209.205.218.43';\r\n\r\n\/\/ Use JSON encoded string and converts\r\n\/\/ it into a PHP variable\r\n$ipdat = @json_decode(file_get_contents(\r\n\t\"http:\/\/www.geoplugin.net\/json.gp?ip=\" . $ip));\r\n\r\necho 'Country Name: ' . $ipdat->geoplugin_countryName . \"&lt;\/br>\";\r\necho 'City Name: ' . $ipdat->geoplugin_city . \"&lt;\/br>\";\r\necho 'Continent Name: ' . $ipdat->geoplugin_continentName . \"&lt;\/br>\";\r\necho 'Latitude: ' . $ipdat->geoplugin_latitude . \"&lt;\/br>\";\r\necho 'Longitude: ' . $ipdat->geoplugin_longitude . \"&lt;\/br>\";\r\necho 'Currency Symbol: ' . $ipdat->geoplugin_currencySymbol . \"&lt;\/br>\";\r\necho 'Currency Code: ' . $ipdat->geoplugin_currencyCode . \"&lt;\/br>\";\r\necho 'Timezone: ' . $ipdat->geoplugin_timezone;\r\n\r\n?>\n\n<strong>Output in browser:<\/strong>\n\n<strong>\n<\/strong>\n\n<\/code><\/pre><figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"373\" src=\"https:\/\/lookouthost.com\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp-1024x373.png\" alt=\"\" class=\"wp-image-1162\" srcset=\"https:\/\/lookouthost.com\/blog\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp-1024x373.png 1024w, https:\/\/lookouthost.com\/blog\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp-600x218.png 600w, https:\/\/lookouthost.com\/blog\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp-300x109.png 300w, https:\/\/lookouthost.com\/blog\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp-768x280.png 768w, https:\/\/lookouthost.com\/blog\/wp-content\/uploads\/2022\/07\/getcountrycodeinphp.png 1360w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>","protected":false},"excerpt":{"rendered":"<p>This example shows how to get a visitor&#8217;s country using their ip in PHP language. This script doesn&#8217;t show how to get ip which we will discuss in another article.<\/p>\n","protected":false},"author":1,"featured_media":1161,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[],"class_list":["post-1160","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-php"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/posts\/1160","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/comments?post=1160"}],"version-history":[{"count":0,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/posts\/1160\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/media\/1161"}],"wp:attachment":[{"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/media?parent=1160"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/categories?post=1160"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/lookouthost.com\/blog\/wp-json\/wp\/v2\/tags?post=1160"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}