从maxmind javascript中检索数据库

时间:2014-09-30 09:13:32

标签: javascript php maxmind

我正在尝试通过maxmind检索国家/地区代码 javascript 但返回null为什么? **希望按国家/地区代码获取时区。**

一旦我获得了国家代码,我就想要它。我在这里得到了时区。但是javascript返回null

https://github.com/maxromanovsky/php-maxmind-geoip/blob/master/timezone/timezone.php

 <script src="http://j.maxmind.com/app/geoip.js"></script>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script type="text/javascript">
    $("#country").html( 'Country: ' + geoip_country_code() );
    <?php $country = geoip_country_code(); ?>
    </script>
<div id="country"></div>

1 个答案:

答案 0 :(得分:0)

您是否有http://j.maxmind.com/app/geoip.js的本地副本,因为500 Internals服务器错误将返回给我。你也没有正确使用它,首先你需要在页面加载时geoip_country_code();,如果这实际上是JS函数,我不会得到PHP部分,因为PHP MaxMind中没有这样的函数代码geoip_country_code()。在您的php中执行以下操作

<?php
include('geoip.inc');
include('geoipregionvars.php');
include('timezone/timezone.php');

$gi = geoip_open(PATH_TO_GeoIP.dat,GEOIP_STANDARD);

list($country_code,$region) = geoip_region_by_addr($gi, $IP_ADDRESS);
$timeZone = get_time_zone($country_code,$region);
相关问题