Php 如何创建重定向页面到新页面
我不是专家,但我试图监控我的流量,我试图用代码创建一个页面,检测用户的地理位置并将他们重定向到新页面 但它看起来好像少了什么,我不知道是什么 我试着用这个 但是我找不到我从哪里得到这个GeoIP.php 有人能告诉我需要什么来让它工作吗 谢谢Php 如何创建重定向页面到新页面,php,redirect,geoip,Php,Redirect,Geoip,我不是专家,但我试图监控我的流量,我试图用代码创建一个页面,检测用户的地理位置并将他们重定向到新页面 但它看起来好像少了什么,我不知道是什么 我试着用这个 但是我找不到我从哪里得到这个GeoIP.php 有人能告诉我需要什么来让它工作吗 谢谢 波阿斯你应该看看这个: 简单使用 $country = geoip_continent_code_by_name ( $_SERVER['REMOTE_ADDR'] ); $country将返回两个字母的国家/地区代码。以下是您应该能够使用的: <
波阿斯你应该看看这个: 简单使用
$country = geoip_continent_code_by_name ( $_SERVER['REMOTE_ADDR'] );
$country将返回两个字母的国家/地区代码。以下是您应该能够使用的:
<?php
//Get the country code of the user, using REMOTE_ADDR is the most reliable way to do this
$country = geoip_continent_code_by_name ( $_SERVER['REMOTE_ADDR'] );
//Create a switch case to deal with the country codes
switch((string)$country) {
case 'AU':
$url = "http://www.site.au";
break;
case 'CA':
$url = "http://www.site.ca";
break;
//default case means, if you didn't provide a case (country code in your example), do this (otherwise known as a "catch all")
default:
$url = "http://defaultsite.com";
} //End switchcase
//This if statement says as long as $url is not empty (! means not), update header location (this is the php way of forwarding)
if ( !empty($url) ){
header('Location: '.$url);
} //End if statement
?>
GeoIP.php是我认为的来源。如果你从我的帖子中了解到我不是专家,我需要有助于完成这项工作的代码,我完全是个傻瓜