1. <i id='R01Qi'><tr id='R01Qi'><dt id='R01Qi'><q id='R01Qi'><span id='R01Qi'><b id='R01Qi'><form id='R01Qi'><ins id='R01Qi'></ins><ul id='R01Qi'></ul><sub id='R01Qi'></sub></form><legend id='R01Qi'></legend><bdo id='R01Qi'><pre id='R01Qi'><center id='R01Qi'></center></pre></bdo></b><th id='R01Qi'></th></span></q></dt></tr></i><div id='R01Qi'><tfoot id='R01Qi'></tfoot><dl id='R01Qi'><fieldset id='R01Qi'></fieldset></dl></div>
    • <bdo id='R01Qi'></bdo><ul id='R01Qi'></ul>

    <small id='R01Qi'></small><noframes id='R01Qi'>

      <tfoot id='R01Qi'></tfoot>

      <legend id='R01Qi'><style id='R01Qi'><dir id='R01Qi'><q id='R01Qi'></q></dir></style></legend>

      您如何检测网站访问者的国家/地区(特别是美国与否)?

      时间:2024-08-14
    1. <i id='SfrUc'><tr id='SfrUc'><dt id='SfrUc'><q id='SfrUc'><span id='SfrUc'><b id='SfrUc'><form id='SfrUc'><ins id='SfrUc'></ins><ul id='SfrUc'></ul><sub id='SfrUc'></sub></form><legend id='SfrUc'></legend><bdo id='SfrUc'><pre id='SfrUc'><center id='SfrUc'></center></pre></bdo></b><th id='SfrUc'></th></span></q></dt></tr></i><div id='SfrUc'><tfoot id='SfrUc'></tfoot><dl id='SfrUc'><fieldset id='SfrUc'></fieldset></dl></div>
        <tbody id='SfrUc'></tbody>

          <legend id='SfrUc'><style id='SfrUc'><dir id='SfrUc'><q id='SfrUc'></q></dir></style></legend>

          <small id='SfrUc'></small><noframes id='SfrUc'>

              • <bdo id='SfrUc'></bdo><ul id='SfrUc'></ul>

              • <tfoot id='SfrUc'></tfoot>
                本文介绍了您如何检测网站访问者的国家/地区(特别是美国与否)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我需要为访问我网站的美国和非美国访问者显示不同的链接.这只是为了方便起见,所以我不是在寻找超高的准确性,而且安全或欺骗不是问题.

                I need to show different links for US and non-US visitors to my site. This is for convenience only, so I am not looking for a super-high degree of accuracy, and security or spoofing are not a concern.

                我知道有地理定位服务和列表,但这似乎有点过头了,因为我只需要(大致)确定此人是否在美国.

                I know there are geotargeting services and lists, but this seems like overkill since I only need to determine (roughly) if the person is in the US or not.

                我正在考虑使用 JavaScript 来获取用户的时区,但这似乎只给出了偏移量,因此加拿大、墨西哥和南美的用户将具有与美国用户相同的价值.

                I was thinking about using JavaScript to get the user's timezone, but this appears to only give the offset, so users in Canada, Mexico, and South America would have the same value as people in the US.

                除了获取 IP 地址并进行查找之外,还有其他可用的 JavaScript 或 PHP 信息吗?

                Are there any other bits of information available either in JavaScript, or PHP, short of grabbing the IP address and doing a lookup, to determine this?

                推荐答案

                有一些免费服务可以让您从客户端进行基于国家和 ip 的地理定位.

                There are some free services out there that let you make country and ip-based geolocalization from the client-side.

                我用过wipmania免费的JSONP服务,用起来真的很简单:

                I've used the wipmania free JSONP service, it's really simple to use:

                <script type="text/javascript">
                  // plain JavaScript example
                  function jsonpCallback(data) { 
                    alert('Latitude: ' + data.latitude + 
                          '
                Longitude: ' + data.longitude + 
                          '
                Country: ' + data.address.country); 
                  }
                </script>
                <script src="http://api.wipmania.com/jsonp?callback=jsonpCallback"
                        type="text/javascript"></script>
                

                或者,如果您使用支持 JSONP 的框架,例如 jQuery,您可以:

                Or if you use a framework that supports JSONP, like jQuery you can:

                // jQuery example
                $.getJSON('http://api.wipmania.com/jsonp?callback=?', function (data) { 
                  alert('Latitude: ' + data.latitude + 
                        '
                Longitude: ' + data.longitude + 
                        '
                Country: ' + data.address.country); 
                });
                

                检查上面运行的代码段这里.

                Check the above snippet running here.

                这篇关于您如何检测网站访问者的国家/地区(特别是美国与否)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:您如何处理 PHP 中的时区差异计算? 下一篇:在 PHP 中处理在不同时区存储/显示日期的最佳方法?

                相关文章

              • <small id='2QkRw'></small><noframes id='2QkRw'>

                <legend id='2QkRw'><style id='2QkRw'><dir id='2QkRw'><q id='2QkRw'></q></dir></style></legend>

                    <bdo id='2QkRw'></bdo><ul id='2QkRw'></ul>
                1. <i id='2QkRw'><tr id='2QkRw'><dt id='2QkRw'><q id='2QkRw'><span id='2QkRw'><b id='2QkRw'><form id='2QkRw'><ins id='2QkRw'></ins><ul id='2QkRw'></ul><sub id='2QkRw'></sub></form><legend id='2QkRw'></legend><bdo id='2QkRw'><pre id='2QkRw'><center id='2QkRw'></center></pre></bdo></b><th id='2QkRw'></th></span></q></dt></tr></i><div id='2QkRw'><tfoot id='2QkRw'></tfoot><dl id='2QkRw'><fieldset id='2QkRw'></fieldset></dl></div>

                    <tfoot id='2QkRw'></tfoot>