{"id":2584,"date":"2020-01-24T16:18:34","date_gmt":"2020-01-24T16:18:34","guid":{"rendered":"https:\/\/ibex.tech\/cloud\/?p=2584"},"modified":"2022-02-17T07:13:48","modified_gmt":"2022-02-17T07:13:48","slug":"read-users-country-code","status":"publish","type":"post","link":"https:\/\/ibex.tech\/cloud\/platforms\/cloudflare\/geolocation\/read-users-country-code","title":{"rendered":"Read users country code"},"content":{"rendered":"\n<h5 class=\"wp-block-heading\">Enable Geolocation in cloudflare<\/h5>\n\n\n\n<p>Cloudflare settings > Network > IP Geolocation = On<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">Reading the value<\/h5>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/Read cloudflare provided country code of user\n  $UserCountryCode = '';\n  if(isset($_SERVER&#91;\"HTTP_CF_IPCOUNTRY\"]))          \/\/Look for cloudflare country code added to request headers\n    $UserCountryCode = $_SERVER&#91;\"HTTP_CF_IPCOUNTRY\"];<\/code><\/pre>\n\n\n\n<p>Gives you the country of the user in <a href=\"https:\/\/en.wikipedia.org\/wiki\/ISO_3166-1_alpha-2\">ISO 3166-1 Alpha 2 format<\/a>. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>Enable Geolocation in cloudflare Cloudflare settings > Network > IP Geolocation = On Reading the value Gives you the country of the user in ISO 3166-1 Alpha 2 format.<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[227],"tags":[],"class_list":["post-2584","post","type-post","status-publish","format-standard","hentry","category-geolocation"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2584","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/comments?post=2584"}],"version-history":[{"count":2,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2584\/revisions"}],"predecessor-version":[{"id":2586,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/posts\/2584\/revisions\/2586"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/media?parent=2584"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/categories?post=2584"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/cloud\/wp-json\/wp\/v2\/tags?post=2584"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}