json - Country name in PHP, not showing -


i have problem code wrote. i've tested code several times , working fine, thing if run php file in 1 specific server (namecheap) there functions don't work correctly , when run in server (1and1) goes 100% well. want country name based on ip stablish market , have code in namecheap, $country_name not shown in 1and1 certenly does. i'm wondering if has php version? if guys, can refer me documentation see if i'm capable solve on own.

i hope i'm being clear enough. in advance.

links of file on servers here namecheap , 1and1

here php code:

<?php  /* --------------------------------------- /  * xx. ip , country (market).  * -------------------------------------- */  // gets client's ip. $ip = getenv("http_client_ip")?: getenv("http_x_forwarded_for")?: getenv("http_x_forwarded")?: getenv("http_forwarded_for")?: getenv("http_forwarded")?: getenv("remote_addr");  // matchs gotten ip api values , retrives location value. $location = json_decode(file_get_contents("http://ipinfo.io/{$ip}"));  // "country code name" array. $countries = array( "bd" => "bangladesh", "be" => "belgium", "bf" => "burkina faso", "bg" => "bulgaria", "ba" => "bosnia , herzegovina", "bb" => "barbados", "wf" => "wallis , futuna", "bl" => "saint barthelemy", "bm" => "bermuda", "bn" => "brunei", "bo" => "bolivia", "bh" => "bahrain", "bi" => "burundi", "bj" => "benin", "bt" => "bhutan", "jm" => "jamaica", "bv" => "bouvet island", "bw" => "botswana", "ws" => "samoa", "bq" => "bonaire, saint eustatius , saba ", "br" => "brazil", "bs" => "bahamas", "je" => "jersey", "by" => "belarus", "bz" => "belize", "ru" => "russia", "rw" => "rwanda", "rs" => "serbia", "tl" => "east timor", "re" => "reunion", "tm" => "turkmenistan", "tj" => "tajikistan", "ro" => "romania", "tk" => "tokelau", "gw" => "guinea-bissau", "gu" => "guam", "gt" => "guatemala", "gs" => "south georgia , south sandwich islands", "gr" => "greece", "gq" => "equatorial guinea", "gp" => "guadeloupe", "jp" => "japan", "gy" => "guyana", "gg" => "guernsey", "gf" => "french guiana", "ge" => "georgia", "gd" => "grenada", "gb" => "united kingdom", "ga" => "gabon", "sv" => "el salvador", "gn" => "guinea", "gm" => "gambia", "gl" => "greenland", "gi" => "gibraltar", "gh" => "ghana", "om" => "oman", "tn" => "tunisia", "jo" => "jordan", "hr" => "croatia", "ht" => "haiti", "hu" => "hungary", "hk" => "hong kong", "hn" => "honduras", "hm" => "heard island , mcdonald islands", "ve" => "venezuela", "pr" => "puerto rico", "ps" => "palestinian territory", "pw" => "palau", "pt" => "portugal", "sj" => "svalbard , jan mayen", "py" => "paraguay", "iq" => "iraq", "pa" => "panama", "pf" => "french polynesia", "pg" => "papua new guinea", "pe" => "peru", "pk" => "pakistan", "ph" => "philippines", "pn" => "pitcairn", "pl" => "poland", "pm" => "saint pierre , miquelon", "zm" => "zambia", "eh" => "western sahara", "ee" => "estonia", "eg" => "egypt", "za" => "south africa", "ec" => "ecuador", "it" => "italy", "vn" => "vietnam", "sb" => "solomon islands", "et" => "ethiopia", "so" => "somalia", "zw" => "zimbabwe", "sa" => "saudi arabia", "es" => "spain", "er" => "eritrea", "me" => "montenegro", "md" => "moldova", "mg" => "madagascar", "mf" => "saint martin", "ma" => "morocco", "mc" => "monaco", "uz" => "uzbekistan", "mm" => "myanmar", "ml" => "mali", "mo" => "macao", "mn" => "mongolia", "mh" => "marshall islands", "mk" => "macedonia", "mu" => "mauritius", "mt" => "malta", "mw" => "malawi", "mv" => "maldives", "mq" => "martinique", "mp" => "northern mariana islands", "ms" => "montserrat", "mr" => "mauritania", "im" => "isle of man", "ug" => "uganda", "tz" => "tanzania", "my" => "malaysia", "mx" => "mexico", "il" => "israel", "fr" => "france", "io" => "british indian ocean territory", "sh" => "saint helena", "fi" => "finland", "fj" => "fiji", "fk" => "falkland islands", "fm" => "micronesia", "fo" => "faroe islands", "ni" => "nicaragua", "nl" => "netherlands", "no" => "norway", "na" => "namibia", "vu" => "vanuatu", "nc" => "new caledonia", "ne" => "niger", "nf" => "norfolk island", "ng" => "nigeria", "nz" => "new zealand", "np" => "nepal", "nr" => "nauru", "nu" => "niue", "ck" => "cook islands", "xk" => "kosovo", "ci" => "ivory coast", "ch" => "switzerland", "co" => "colombia", "cn" => "china", "cm" => "cameroon", "cl" => "chile", "cc" => "cocos islands", "ca" => "canada", "cg" => "republic of congo", "cf" => "central african republic", "cd" => "democratic republic of congo", "cz" => "czech republic", "cy" => "cyprus", "cx" => "christmas island", "cr" => "costa rica", "cw" => "curacao", "cv" => "cape verde", "cu" => "cuba", "sz" => "swaziland", "sy" => "syria", "sx" => "sint maarten", "kg" => "kyrgyzstan", "ke" => "kenya", "ss" => "south sudan", "sr" => "suriname", "ki" => "kiribati", "kh" => "cambodia", "kn" => "saint kitts , nevis", "km" => "comoros", "st" => "sao tome , principe", "sk" => "slovakia", "kr" => "south korea", "si" => "slovenia", "kp" => "north korea", "kw" => "kuwait", "sn" => "senegal", "sm" => "san marino", "sl" => "sierra leone", "sc" => "seychelles", "kz" => "kazakhstan", "ky" => "cayman islands", "sg" => "singapore", "se" => "sweden", "sd" => "sudan", "do" => "dominican republic", "dm" => "dominica", "dj" => "djibouti", "dk" => "denmark", "vg" => "british virgin islands", "de" => "germany", "ye" => "yemen", "dz" => "algeria", "us" => "united states", "uy" => "uruguay", "yt" => "mayotte", "um" => "united states minor outlying islands", "lb" => "lebanon", "lc" => "saint lucia", "la" => "laos", "tv" => "tuvalu", "tw" => "taiwan", "tt" => "trinidad , tobago", "tr" => "turkey", "lk" => "sri lanka", "li" => "liechtenstein", "lv" => "latvia", "to" => "tonga", "lt" => "lithuania", "lu" => "luxembourg", "lr" => "liberia", "ls" => "lesotho", "th" => "thailand", "tf" => "french southern territories", "tg" => "togo", "td" => "chad", "tc" => "turks , caicos islands", "ly" => "libya", "va" => "vatican", "vc" => "saint vincent , grenadines", "ae" => "united arab emirates", "ad" => "andorra", "ag" => "antigua , barbuda", "af" => "afghanistan", "ai" => "anguilla", "vi" => "u.s. virgin islands", "is" => "iceland", "ir" => "iran", "am" => "armenia", "al" => "albania", "ao" => "angola", "aq" => "antarctica", "as" => "american samoa", "ar" => "argentina", "au" => "australia", "at" => "austria", "aw" => "aruba", "in" => "india", "ax" => "aland islands", "az" => "azerbaijan", "ie" => "ireland", "id" => "indonesia", "ua" => "ukraine", "qa" => "qatar", "mz" => "mozambique" );  // assigns location value variable "&country_code". $country_code = $location->country;  // holds country name value after checking array. $country_name = $countries[$country_code];  // posted data. $posted_data["market"] = $country_name;  // holds ip value. $posted_data["ip-address"] = $ip;  /* end of ip , country (market) */  echo 'ip address: ' . $ip . '<br>country: ' . $country_name; 

according ipinfo documentation should use curl function not file_get_content witch gets webpage result not json data.

curl ipinfo.io/8.8.8.8 {   "ip": "8.8.8.8",   "hostname": "google-public-dns-a.google.com",   "loc": "37.385999999999996,-122.0838",   "org": "as15169 google inc.",   "city": "mountain view",   "region": "california",   "country": "us",   "phone": 650 } 

documentation here

here example php curl:

<?php $ch = curl_init();  curl_setopt($ch, curlopt_url, "http://ipinfo.io/8.8.8.8"); curl_setopt($ch, curlopt_header, 0); curl_setopt($ch, curlopt_returntransfer , true);  $result=curl_exec($ch);  //print_r($result);  $jsonresult = json_decode($result);  echo "country: ".$jsonresult->country;  curl_close($ch); ?> 

i hope can you.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -