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");
}
?>

最新文章

  1. 网站中使用echart
  2. Cable TV Network-POJ1966图的连通度
  3. 前端翻译:Activating Browser Modes with Doctype
  4. 【OpenCV】选择ROI区域
  5. JS练习 改变文本框状态
  6. 0511 backlog 项目管理
  7. RHEL7全新初始化进程管理systemd(图形启动和非图形启动切换)
  8. js 字符及字符串
  9. [学习笔记]设计模式之Chain of Responsibility
  10. UVALive3516Exploring Pyramids(dp)
  11. 一个简单的带缓存http代理
  12. 2017人生总结(MECE分析法)
  13. hdu5586 BestCoder Round #64 (div.2)
  14. js 属性增改删操作
  15. jd-gui在Ubuntu上打不开
  16. 第 8 章 容器网络 - 052 - overlay 如何实现跨主机通信?
  17. CURLOPT_RETURNTRANSFER
  18. 关于SpringBoot开发微信模板推送
  19. 【LGP4886 】快递员
  20. 20162314 《Program Design &amp; Data Structures》Learning Summary Of The Ninth Week

热门文章

  1. 跟我一起学习VIM - The Life Changing Editor
  2. less-2
  3. HDOJ2006求奇数的乘积
  4. 北大ACM(POJ1002-487-3279)
  5. 在SQL 2012中使用和Oracle 一样的序列
  6. selenium Grid(一)
  7. Today&rsquo;s words
  8. pl/sql developer 中文字段显示乱码
  9. FAILURE: Build failed with an exception. Crunching Cruncher screen.png failed
  10. Poj 2109 / OpenJudge 2109 Power of Cryptography