在php中获取用户国家代码

时间:2013-07-06 08:40:34

标签: php javascript jquery

我需要在访问我的网站时获取用户的国家/地区代码。 我正在使用这个JS代码,它的工作正常,但我需要使用php。

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
</head>
<body></body> 
   <script type="text/javascript">


        function geoTest() {
            if (google.loader.ClientLocation) {
            var country_code = google.loader.ClientLocation.address.country_code;
            var text = country_code;
            } else {
                var text = 'Google was not able to detect your location';
            }
            document.body.innerHTML = text;
        }
        geoTest();
    </script>
</html>

我搜索了谷歌是否有一个php api,事实证明他们没有。知道如何在访问我的网站时获取用户国家代码吗?例如使用他或她的IP?

0 个答案:

没有答案