使用GeoIP获取IP区域信息

<?php

    //计时开始
    function utime() {
        $time = explode( " ", microtime() );
        $usec = (double)$time[0];
        $sec = (double)$time[1];
        return $usec + $sec;
    }
    $startTimes = utime();
 
    // include the php script
    // wget -c http://geolite.maxmind.com/download/geoip/database/GeoLiteCountry/GeoIP.dat.gz
    // gunzip GeoIP.dat.gz
    include("geoip.inc");
 
    // open the geoip database
    $gi = geoip_open("GeoIP.dat",GEOIP_STANDARD);
 
    // 获取国家代码
    $country_code = geoip_country_code_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    echo "Your country code is: <strong>$country_code</strong> <br />";
 
    // 获取国家名称
    $country_name = geoip_country_name_by_addr($gi, $_SERVER['REMOTE_ADDR']);
    echo "Your country name is: <strong>$country_name</strong> <br />";
 
    // close the database
    geoip_close($gi);
 
    //运行结束时间
    $endTimes = utime();
    $runTimes = sprintf( '%0.4f', ( $endTimes - $startTimes ) );
    echo "Processed in " . $runTimes . "second.";
?>

可实现piwik的地图区域展示

参考:http://piwik.org/docs/visitors-map/



转载于:https://my.oschina.net/linland/blog/373295

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值