根据不同ip进入不同页面
2024-10-16 08:43:19
function GetIP()
{
$cip = "";
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$cip = $_SERVER["HTTP_CLIENT_IP"];
}
if(!empty($_SERVER["REMOTE_ADDR"])){
$cip = $_SERVER["REMOTE_ADDR"];
}
if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
return $cip;
}
$ch = curl_init();
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.GetIP();
$json = file_get_contents($url);
$ip_data = json_decode($json, true);
/*$header = array(
'apikey:a49f5d21a5deead357e9faf3895f0907',
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行HTTP请求
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
$ip_data = json_decode($res,true);*/
$ipaddress = $ip_data['retData']['province'].$ip_data['retData']['city'];
if(strpos($ipaddress,'北京')===false){
header("Location:index(tuibeifen).php");
}
推荐:
<?php
function GetIP()
{
$cip = "";
if(!empty($_SERVER["HTTP_CLIENT_IP"])){
$cip = $_SERVER["HTTP_CLIENT_IP"];
}
if(!empty($_SERVER["REMOTE_ADDR"])){
$cip = $_SERVER["REMOTE_ADDR"];
}
if(!empty($_SERVER["HTTP_X_FORWARDED_FOR"])){
$cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
}
return $cip;
}
$ch = curl_init();
$url = 'http://int.dpool.sina.com.cn/iplookup/iplookup.php?format=json&ip='.GetIP();
$json = file_get_contents($url);
$ip_data = json_decode($json, true);
/*$header = array(
'apikey:a49f5d21a5deead357e9faf3895f0907',
);
// 添加apikey到header
curl_setopt($ch, CURLOPT_HTTPHEADER , $header);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
// 执行HTTP请求
curl_setopt($ch , CURLOPT_URL , $url);
$res = curl_exec($ch);
$ip_data = json_decode($res,true);*/
$ipaddress = $ip_data['province'].$ip_data['city'];
if(strpos($ipaddress,'北京')===false){
header("Location:../huangheban/index.php");
}
?>
最新文章
- 网站中使用echart
- Cable TV Network-POJ1966图的连通度
- 前端翻译:Activating Browser Modes with Doctype
- 【OpenCV】选择ROI区域
- JS练习 改变文本框状态
- 0511 backlog 项目管理
- RHEL7全新初始化进程管理systemd(图形启动和非图形启动切换)
- js 字符及字符串
- [学习笔记]设计模式之Chain of Responsibility
- UVALive3516Exploring Pyramids(dp)
- 一个简单的带缓存http代理
- 2017人生总结(MECE分析法)
- hdu5586 BestCoder Round #64 (div.2)
- js 属性增改删操作
- jd-gui在Ubuntu上打不开
- 第 8 章 容器网络 - 052 - overlay 如何实现跨主机通信?
- CURLOPT_RETURNTRANSFER
- 关于SpringBoot开发微信模板推送
- 【LGP4886 】快递员
- 20162314 《Program Design &; Data Structures》Learning Summary Of The Ninth Week
热门文章
- 跟我一起学习VIM - The Life Changing Editor
- less-2
- HDOJ2006求奇数的乘积
- 北大ACM(POJ1002-487-3279)
- 在SQL 2012中使用和Oracle 一样的序列
- selenium Grid(一)
- Today&rsquo;s words
- pl/sql developer 中文字段显示乱码
- FAILURE: Build failed with an exception. Crunching Cruncher screen.png failed
- Poj 2109 / OpenJudge 2109 Power of Cryptography