<?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/