功能:
1,获取当前IP地址,
2,调用新浪API,获取到当前城市。
3,将中文转换为拼音后跳转。
复制代码 代码如下:
<?php
include './pinyin.php';
//获取当前ip
function getIp(){
$onlineip='';
if(getenv('HTTP_CLIENT_IP')&&strcasecmp(getenv('HTTP_CLIENT_IP'),'unknown')){
$onlineip=getenv('HTTP_CLIENT_IP');
} elseif(getenv('HTTP_X_FORWARDED_FOR')&&strcasecmp(getenv('HTTP_X_FORWARDED_FOR'),'unknown')){
$onlineip=getenv('HTTP_X_FORWARDED_FOR');
} elseif(getenv('REMOTE_ADDR')&&strcasecmp(getenv('REMOTE_ADDR'),'unknown')){
$onlineip=getenv('REMOTE_ADDR');
} elseif(isset($_SERVER['REMOTE_ADDR'])&&$_SERVER['REMOTE_ADDR']&&strcasecmp($_SERVER['REMOTE_ADDR'],'unknown')){
$onlineip=$_SERVER['REMOTE_ADDR'];
}
return $onlineip;
}
//获取城市信息api
function getLocation($ip){
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip=".$ip);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 30);
$str = curl_exec($curl);
curl_close($curl);
return $str;
}
//当前ip地址
$currentIP = getIp();
//通过当前ip获取信息
$getLocation = getLocation($currentIP);
$currentInfo = json_decode($getLocation, true);
//判断ip是否为有效
if($currentInfo['ret'] == '-1')
{
$currentInfo['city'] = 'unknown';
}
//当前城市中文名
$currentCityName = $currentInfo['city'];
$currentCityEName = $pin->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: https://www.jb51.net");
exit;
免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
更新日志
- Rhymist / LusciousBB《年轮》[FLAC/分轨][410.02MB]
- 群星《歌手2024 第11期》[320K/MP3][93.88MB]
- 群星《歌手2024 第11期》[FLAC/分轨][496.06MB]
- 群星《国风超有戏 第7期》[320K/MP3][30.73MB]
- 模拟之声慢刻CD《试音天品8[女声低音炮]》[低速原抓WAV+CUE]
- 群星《抖烧第三季DSD》[低速原抓WAV+CUE]
- [ABC]蔡琴《百万琴歌[6N纯银镀膜]》[低速原抓WAV+CUE]
- 群星《国风超有戏 第7期》[FLAC/分轨][147.99MB]
- 群星《闪光的夏天 第3期》[320K/MP3][61.94MB]
- 群星《闪光的夏天 第3期》[FLAC/分轨][336MB]
- 【迷幻电音】Elea-2024-Hypnos(FLAC)
- 【民族融合】VA-2024-TheOrientCollective:GoldenSand(FLAC)
- 谭嘉仪-EyesOnMe新曲+精选2022【低速原抓WAV+CUE】
- 尚士达《莫回头》[320K/MP3][184.64MB]
- 尚士达《莫回头》[Hi-Res][24bit 48kHz][FLAC/分轨][1.27G]