{"id":1434,"date":"2021-11-12T09:38:10","date_gmt":"2021-11-12T04:08:10","guid":{"rendered":"https:\/\/myfreeonlinetools.com\/blog\/?p=1434"},"modified":"2021-11-12T09:38:51","modified_gmt":"2021-11-12T04:08:51","slug":"get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api","status":"publish","type":"post","link":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/","title":{"rendered":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API"},"content":{"rendered":"<h2>Using GeoPlugin PHP API to Get Country Name and Country IP address.<\/h2>\n<p>&nbsp;<\/p>\n<p>Some time in HTML contact or WordPress contact form 7 we need to Country and Country IP address where the user fills the form. It&#8217;s required for tracking which country user used the form and find out where a lead comes from and which country user using our website lead form. So that requires storing Country name and country IP address in the form of hidden fields. The below code shows how to do this task.<\/p>\n<p>&nbsp;<\/p>\n<h3>PHP Code for getting Country Name and Country IP Address by using Geoplugin PHP API.<\/h3>\n<pre>&lt;?php\r\nif (!empty($_SERVER['HTTP_CLIENT_IP'])) \u00a0 \r\n \u00a0{\r\n$ip = $_SERVER['HTTP_CLIENT_IP'];\r\n \u00a0}\r\nelseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))  \r\n \u00a0{\r\n$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];\r\n \u00a0}\r\nelse\r\n \u00a0{\r\n$ip = $_SERVER['REMOTE_ADDR'];\r\n \u00a0}\r\n\u00a0\u00a0\u00a0\u00a0$data = unserialize(file_get_contents('http:\/\/www.geoplugin.net\/php.gp?ip='.$ip));\r\n \u00a0\u00a0\u00a0$ClientState = \u00a0$data['geoplugin_countryName'];\r\n \u00a0\u00a0\u00a0$ClientIPAddress = $data['geoplugin_request'];\r\n?&gt;<\/pre>\n<h3>jQuery Code for placed or store values in hidden form fields.<\/h3>\n<pre>&lt;script type=\"text\/javascript\"&gt;\r\njQuery(document).ready(function(){\r\njQuery('#countryIPGrow').val('&lt;?php echo $ClientIPAddress;?&gt;');\r\njQuery('#countryLocationGrow').val('&lt;?php echo $ClientState;?&gt;');\r\n});\r\n&lt;\/script&gt;\r\n\r\n<\/pre>\n<h3>HTML Fields for creating Hidden fields in the contact form.<\/h3>\n<pre>&lt;input type=\"hidden\" name=\"countryIPGrow\" id=\"countryIPGrow\" value=\"\"&gt;\r\n&lt;input type=\"hidden\" name=\"countryLocationGrow\" id=\"countryLocationGrow\" value=\"\"&gt;<\/pre>\n<h3>WordPress Contact Form 7 code for creating hidden fields if using WordPress.<\/h3>\n<pre>[hidden countryIP id:countryIPGrow class:countryIPGrow] \u00a0\u00a0\u00a0\r\n\r\n[hidden countryLocation id:countryLocationGrow class:countryLocationGrow]<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Using GeoPlugin PHP API to Get Country Name and Country IP address. &nbsp; Some time in HTML contact or WordPress contact form 7 we need to Country and Country IP [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[29,26],"tags":[],"class_list":["post-1434","post","type-post","status-publish","format-standard","hentry","category-php","category-wordpress-2"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v24.0 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools\" \/>\n<meta property=\"og:description\" content=\"Using GeoPlugin PHP API to Get Country Name and Country IP address. &nbsp; Some time in HTML contact or WordPress contact form 7 we need to Country and Country IP [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\" \/>\n<meta property=\"og:site_name\" content=\"MyFreeOnlineTools\" \/>\n<meta property=\"article:author\" content=\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\" \/>\n<meta property=\"article:published_time\" content=\"2021-11-12T04:08:10+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2021-11-12T04:08:51+00:00\" \/>\n<meta name=\"author\" content=\"myfreeonlinetools\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"myfreeonlinetools\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\"},\"author\":{\"name\":\"myfreeonlinetools\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\"},\"headline\":\"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API\",\"datePublished\":\"2021-11-12T04:08:10+00:00\",\"dateModified\":\"2021-11-12T04:08:51+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\"},\"wordCount\":151,\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"articleSection\":[\"PHP\",\"WordPress\"],\"inLanguage\":\"en\"},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\",\"name\":\"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools\",\"isPartOf\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\"},\"datePublished\":\"2021-11-12T04:08:10+00:00\",\"dateModified\":\"2021-11-12T04:08:51+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#breadcrumb\"},\"inLanguage\":\"en\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/myfreeonlinetools.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#website\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"name\":\"MyFreeOnlineTools\",\"description\":\"\",\"publisher\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#organization\",\"name\":\"MyFreeOnlineTools\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"contentUrl\":\"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png\",\"width\":387,\"height\":79,\"caption\":\"MyFreeOnlineTools\"},\"image\":{\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c\",\"name\":\"myfreeonlinetools\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en\",\"@id\":\"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g\",\"caption\":\"myfreeonlinetools\"},\"description\":\"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.\",\"sameAs\":[\"https:\/\/myfreeonlinetools.com\/\",\"https:\/\/www.facebook.com\/LearnSchoolOnline\/\",\"https:\/\/www.youtube.com\/learnschoolonline\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/","og_locale":"en_US","og_type":"article","og_title":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools","og_description":"Using GeoPlugin PHP API to Get Country Name and Country IP address. &nbsp; Some time in HTML contact or WordPress contact form 7 we need to Country and Country IP [&hellip;]","og_url":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/","og_site_name":"MyFreeOnlineTools","article_author":"https:\/\/www.facebook.com\/LearnSchoolOnline\/","article_published_time":"2021-11-12T04:08:10+00:00","article_modified_time":"2021-11-12T04:08:51+00:00","author":"myfreeonlinetools","twitter_card":"summary_large_image","twitter_misc":{"Written by":"myfreeonlinetools","Est. reading time":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#article","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/"},"author":{"name":"myfreeonlinetools","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c"},"headline":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API","datePublished":"2021-11-12T04:08:10+00:00","dateModified":"2021-11-12T04:08:51+00:00","mainEntityOfPage":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/"},"wordCount":151,"publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"articleSection":["PHP","WordPress"],"inLanguage":"en"},{"@type":"WebPage","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/","url":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/","name":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API - MyFreeOnlineTools","isPartOf":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#website"},"datePublished":"2021-11-12T04:08:10+00:00","dateModified":"2021-11-12T04:08:51+00:00","breadcrumb":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#breadcrumb"},"inLanguage":"en","potentialAction":[{"@type":"ReadAction","target":["https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/myfreeonlinetools.com\/blog\/get-country-name-and-ip-address-in-form-hidden-field-by-php-geoplugin-api\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/myfreeonlinetools.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Get Country Name and IP Address in Form Hidden Field by PHP Geoplugin API"}]},{"@type":"WebSite","@id":"https:\/\/myfreeonlinetools.com\/blog\/#website","url":"https:\/\/myfreeonlinetools.com\/blog\/","name":"MyFreeOnlineTools","description":"","publisher":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/myfreeonlinetools.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en"},{"@type":"Organization","@id":"https:\/\/myfreeonlinetools.com\/blog\/#organization","name":"MyFreeOnlineTools","url":"https:\/\/myfreeonlinetools.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","contentUrl":"https:\/\/myfreeonlinetools.com\/blog\/wp-content\/uploads\/2019\/11\/myfreeonlinetools-blue.png","width":387,"height":79,"caption":"MyFreeOnlineTools"},"image":{"@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/b1eb72e57c554e3b33cfeec477efcc3c","name":"myfreeonlinetools","image":{"@type":"ImageObject","inLanguage":"en","@id":"https:\/\/myfreeonlinetools.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/b870b17c6c7e3b75d7fe0b8bebfc9cf5?s=96&d=mm&r=g","caption":"myfreeonlinetools"},"description":"Live in Delhi, Working in Gurgaon as Web Designer and Graphic Designer. Developed and Design myfreeonlinetools for online free tools. Also having youtube channel Name with LearnSchoolOnline. Traveling, watching movies, coding are the hobbies.","sameAs":["https:\/\/myfreeonlinetools.com\/","https:\/\/www.facebook.com\/LearnSchoolOnline\/","https:\/\/www.youtube.com\/learnschoolonline"]}]}},"_links":{"self":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1434","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/comments?post=1434"}],"version-history":[{"count":0,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/posts\/1434\/revisions"}],"wp:attachment":[{"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/media?parent=1434"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/categories?post=1434"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myfreeonlinetools.com\/blog\/wp-json\/wp\/v2\/tags?post=1434"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}