当用户登陆 site.com/redirect.php 时,我可以轻松使用此脚本,他们会根据地理 IP 重定向到适当的 TLD,但是当我在“index.php”中添加此代码时,它会创建一个重定向循环。你能帮我修改它,使它不会产生循环吗?现在这个“休息”没有帮助..
<?php
// Next two lines are for Beyond Hosting
// Don't forget to change your-domain
require_once '/home/your-domain/php/Net/GeoIP.php';
$geoip = Net_GeoIP::getInstance('/home/your-domain/php/Net/GeoIP.dat');
// Next two lines are for HostGator
require_once 'Net/GeoIP.php';
$geoip = Net_GeoIP::getInstance('GeoIP.dat');
try {
$country = $geoip->lookupCountryCode($_SERVER['REMOTE_ADDR']);
switch((string)$country) {
case 'AU':
$url = "http://www.site.au";
break;
case 'CA':
$url = "http://www.site.ca";
break;
default:
$url = "http://site.com";
}
header('Location: '.$url);
} catch (Exception $e) {
// Handle exception
}
?>