Amy1980 Posted January 2, 2007 Share Posted January 2, 2007 Hello. In my little guestbook script I wanna to getting user country. I think about HTTP_ACCEPT_LANGUAGE but I have some problems with it.I got this country table:[code]<?php$country = array( "ad" => "Andorra", "ae" => "Vereinigte Arabische Emirate", "af" => "Afghanistan", "ag" => "Antigua und Barbuda", "ai" => "Anguilla", "al" => "Albanien", "am" => "Armenien", "an" => "Netherlands Antilles", "ao" => "Angola", "ar" => "Argentinien", "at" => "Österreich", "au" => "Australien", "az" => "Aserbaidschan", "ba" => "Bosnien und Herzegowina", "bb" => "Barbados", "bd" => "Bangladesch", "be" => "Belgien", "bf" => "Burkina Faso", "bg" => "Bulgarien", "bh" => "Bahrain", "bi" => "Burundi", "bj" => "Benin", "bm" => "Bermuda", "bn" => "Bruneo", "bo" => "Bolivien", "br" => "Brasilien", "by" => "Weißrussland", "bz" => "Belize", "ca" => "Kanada", "ch" => "Switzerland", "cl" => "Chile", "cm" => "Cameroon", "cn" => "China", "co" => "Colombia", "cr" => "Costa Rica", "cs" => "Serbien", "cu" => "Kuba", "cy" => "Zypern", "cz" => "Tschechien", "de" => "Deutschland", "dk" => "Dńnemark", "dm" => "Dominica", "do" => "Dominikanische Republik", "dz" => "Algerien", "ec" => "Ecuador", "ee" => "Estland", "eg" => "Ägypten", "er" => "Eritrea", "es" => "Spanien", "et" => "Äthiopien", "fi" => "Finnland", "fj" => "Fidschi", "fr" => "Frankreich", "ga" => "Gabon", "ge" => "Georgien", "gh" => "Ghana", "gm" => "Gambia", "gn" => "Guinea", "gp" => "Guadeloupe", "gr" => "Griechenland", "gt" => "Guatemala", "gw" => "Guinea-Bissau", "gy" => "Guyana", "hn" => "Honduras", "hr" => "Kroatien", "ht" => "Haiti", "hu" => "Ungarn", "id" => "Indonesien", "ie" => "Irland", "il" => "Israel", "in" => "Indien", "iq" => "Irak", "ir" => "Iran", "is" => "Iseland", "it" => "Italien", "jm" => "Jamaika", "jo" => "Jordanien", "jp" => "Japan", "ke" => "Kenia", "kg" => "Kirgisistan", "kh" => "Kambodscha", "kp" => "Korea, Demokratische Volksrepublik", "kr" => "Korea, Republik", "kw" => "Kuwait", "kz" => "Kazachstan", "la" => "Laos", "lb" => "Libanon", "li" => "Liechtenstein", "lk" => "Sri Lanka", "lr" => "Liberia", "ls" => "Lesotho", "lt" => "Litauen", "lu" => "Luxemburg", "lv" => "Lettland", "ly" => "Libyen", "ma" => "Morokko", "mc" => "Monaco", "md" => "Moldawien", "mg" => "Madagaskar", "mh" => "Marshallinseln", "mk" => "Mazedonien", "ml" => "Mali", "mn" => "Mongolei", "mr" => "Mauritanien", "mt" => "Malta", "mx" => "Mexicko", "my" => "Malaysia", "mz" => "Mosambik", "na" => "Namibia", "ne" => "Niger", "ng" => "Nigeria", "ni" => "Nicaragua", "nl" => "Niederlande", "no" => "Norwegen", "np" => "Nepal", "nz" => "Neuseeland", "om" => "Oman", "pa" => "Panama", "pe" => "Peru", "pg" => "Papua-Neuguinea", "ph" => "Philippinen", "pk" => "Pakistan", "pl" => "Polen", "pr" => "Puerto Rico", "pt" => "Portugal", "py" => "Paraguay", "qa" => "Katar", "ro" => "Rumńnien", "ru" => "Russland", "rw" => "Rwanda", "sa" => "Saudi-Arabien", "sd" => "Sudan", "se" => "Schweden", "si" => "Slovenien", "sk" => "Slovakei", "sl" => "Sierra Leone", "sm" => "San Marino", "sn" => "Senegal", "sy" => "Syrien", "sz" => "Schweiz", "tg" => "Togo", "tm" => "Turkmenistan", "tn" => "Tunesien", "tr" => "Türkei", "tt" => "Trinidad und Tobago", "ua" => "Ukraine", "ug" => "Uganda", "gb" => "Vereinigtes Königreich", "us" => "Vereinigte Staaten", "uy" => "Uruguay", "ve" => "Venezuela", "za" => "Südafrika", "zm" => "Zambia", "zr" => "Zaire", "zw" => "Simbabwe",);?>[/code]I call user lang by:[code]$country = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'], 0, 2));[/code]Hmm. I got problem. As You surely know everything depend of user browser's language. But what to do in case, when user has ex. Arabic[Syria] lang choosen? It returns "ar". It's Argentina's symbol and my script returns Argentinian flag. Have You got any suggestion how to solve it?Greetings and all the best in new year 2007Amy Link to comment https://forums.phpfreaks.com/topic/32608-how-to-get-user-country/ Share on other sites More sharing options...
AV1611 Posted January 2, 2007 Share Posted January 2, 2007 well, you can either change your script to conform to what the browser reports or you can make a cross table that crosses what the browser says to what your script thinks Link to comment https://forums.phpfreaks.com/topic/32608-how-to-get-user-country/#findComment-151668 Share on other sites More sharing options...
Amy1980 Posted January 2, 2007 Author Share Posted January 2, 2007 Could You be so nice and show me what You are thinkin' of on one example?GreetingsAmy Link to comment https://forums.phpfreaks.com/topic/32608-how-to-get-user-country/#findComment-151670 Share on other sites More sharing options...
Amy1980 Posted January 2, 2007 Author Share Posted January 2, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/32608-how-to-get-user-country/#findComment-151719 Share on other sites More sharing options...
BIGjuevos Posted January 2, 2007 Share Posted January 2, 2007 Try a geo-location service that uses the users IP,like this onehttp://www.geobytes.com/IpLocator.htmto determine what you need. Link to comment https://forums.phpfreaks.com/topic/32608-how-to-get-user-country/#findComment-151726 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.