- 安装方法
http://php.net/manual/en/geoip.installation.php
geoip中的PHP函数介绍:
http://php.net/manual/en/book.geoip.php
若Centos安装提示没有程序包,请执行:
rpm -ivh http://ftp.jaist.ac.jp/pub/Linux/Fedora/epel/6/i386/epel-release-6-8.noarch.rpm
Cpanel中安装不成功请参考链接:
http://infantiablue.tumblr.com/post/264539259/install-geoip-on-cpanel-centos-server - 案例
<?php
$countryArray =array(
'USA' //United States
,'GBR' //United Kingdom
,'AUT' //Australia
,'DEU' //Germany
,'ITA' //Italy
,'CAN' //Canada
,'FRA' //France
,'NZL' //New Zealand
,'JPN' //Japan
,'ESP' //Spain
,'CHN' //China
); $fileName = $_GET['fileName'];
if(isset($fileName)){
$country_code = geoip_country_code3_by_name($_SERVER["REMOTE_ADDR"]); if(in_array($country_code, $countryArray))
header("Location: http://www.google.com/".$fileName);
else
header("Location: http://www.baidu.com/".$fileName);
}
?>PHP for geoip
保存上面的代码到PHP文件中,命令为file.php.
访问:http://www.youwebsite.com/file.php?fileName=abc
若访问的IP国家在CountryArray列表中,则链接跳转到:http://www.google.com/abc
若不属于CountryArray列表,则链接到:http://www.baidu.com/abc - 验证geoip是否生效函数
echo $_SERVER["REMOTE_ADDR"].'<br>';
$country_code = geoip_country_code3_by_name($_SERVER["REMOTE_ADDR"]);
$country_code = geoip_country_code3_by_name('58.186.0.0');
echo $country_code.'<br>';
相关文章
- 01-09Maven Spring JUnit 在Maven Clean Install时报
- 01-09VMware安装时出现回滚操作安装提前结束或出现failed to install the hcmon driver提示
- 01-09Instruction for Update and install V2.30 MB SD Connect C4 MUX
- 01-09Tensorflow问题记录 --pydot Failed to import pydot. You must install pydot and graphviz for pydotprint to
- 01-09关于Failed to import pydot. You must install pydot and graphviz for `pydotprint` to work的处理建议
- 01-09file xxx from install of xxx conflicts with file from xxx
- 01-09ML学习笔记之Anaconda中命令形式安装XGBoost(pip install)
- 01-09Deepin 20 (Linux)上安装HeidiSQL
- 01-09什么是’动作android:name =“com.android.vending.INSTALL_REFERRER”’?
- 01-09[linux-012] 用docker搭建greenplum数据库