欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  php教程

获取当前IP地址,跳转到对应城市网站。

程序员文章站 2022-05-07 17:12:07
...

1,通过获取当前IP地址, 2,调用新浪AIP,获取到当前城市。 3,将中文转换为拼音后跳转。 欢迎完善。 无 ?phpinclude './pinyin.php';//获取当前ipfunction getIp(){$onlineip='';if(getenv('HTTP_CLIENT_IP')strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown'

1,通过获取当前IP地址,
2,调用新浪AIP,获取到当前城市。
3,将中文转换为拼音后跳转。

欢迎完善。
Pinyin("$currentCityName",'UTF8');
	
	//城市拼音多音字
	switch($currentCityEName)
	{
		case 'zhongqing':
			$currentCityEName = 'chongqing';
		break;
		
		case 'shenfang':
			$currentCityEName = 'shifang';
		break;
		
		case 'chengdou':
			$currentCityEName = 'chengdu';
		break;
		
		case 'yueshan':
			$currentCityEName = 'leshan';
		break;
		
		case 'junxian':
			$currentCityEName = 'xunxian'; 
		break;
		
		case 'shamen':
			$currentCityEName = 'xiamen'; 
		break;
		
		case 'zhangsha':
			$currentCityEName = 'changsha'; 
		break;
		
		case 'weili':
			$currentCityEName = 'yuli'; 
		break;
		
		case 'zhaoyang':
			$currentCityEName = 'chaoyang'; 
		break;
		
		case 'danxian':
			$currentCityEName = 'shanxian'; 
		break;
		
		default:
			$currentCityEName = $pin->Pinyin("$currentCityName",'UTF8');
		break;
	}
	
	//重定向浏览器 
	header("Location: http://www.huanhang.com/?city=$currentCityEName"); 
	exit;
='5.0') ? array_combine($_TDataKey, $_TDataValue) : $this->Arr_Combine($_TDataKey, $_TDataValue);
		arsort($_Data);
		reset($_Data);
		if($_Code != 'gb2312') $_String = $this->U2_Utf8_Gb($_String);
		$_Res = '';
		for($i=0; $i160) { $_Q = ord(substr($_String, ++$i, 1)); $_P = $_P*256 + $_Q - 65536; }
			$_Res .= $this->Pinyins($_P, $_Data);
		}
		return $_Res;
	}
		
	function Pinyins($_Num, $_Data){
		if ($_Num>0 && $_Num-10247) return '';
		else {
			foreach($_Data as $k=>$v){ if($v>6);
			$_String .= chr(0x80 | $_C & 0x3F);
		}elseif($_C >12);
			$_String .= chr(0x80 | $_C>>6 & 0x3F);
			$_String .= chr(0x80 | $_C & 0x3F);
		}elseif($_C >18);
			$_String .= chr(0x80 | $_C>>12 & 0x3F);
			$_String .= chr(0x80 | $_C>>6 & 0x3F);
			$_String .= chr(0x80 | $_C & 0x3F);
		}
			return iconv('UTF-8', 'GB2312', $_String);
		}
	function Arr_Combine($_Arr1, $_Arr2){
		for($i=0; $iPinyin('北京','UTF8');