PHP屏蔽指定地区访问

远昔 代码记录 2021-11-15 4365 4

半夜起来撸码,偶尔能派上用场,API给你们了 自行开发吧,接口是本人自己运营的,非常稳定靠谱

$data=file_get_contents("https://yuanxiapi.cn/api/iplocation/?ip=".$_SERVER['REMOTE_ADDR']);
$data=json_decode($data,true);

if($data['code']==200){
$diqu='浙江|北京|安徽'; //屏蔽的地区
$array=explode('|',$diqu);
foreach($array as $row){
if(strpos($data['location'],$row)!==false) exit($row.'出现屏蔽地区'); 
}     
}


评论

发表评论:

挤眼 亲亲 咆哮 开心 想想 可怜 糗大了 委屈 哈哈 小声点 右哼哼 左哼哼 疑问 坏笑 赚钱啦 悲伤 耍酷 勾引 厉害 握手 耶 嘻嘻 害羞 鼓掌 馋嘴 抓狂 抱抱 围观 威武 给力
提交评论

清空信息
关闭评论
精彩评论
  • 2022-04-02 03:29:47

    不行,打开是空白页面

    • 2022-04-05 02:42:27

      @访客 已恢复了的,可能你使用那天ip地址查询接口出错了,所以不行

  • 2022-12-02 20:35:49

    ECSHOP用到,谢谢啦!以后多支持哈!

    $real_ip = real_ip();
    $ip_data=file_get_contents("https://yuanxiapi.cn/api/iplocation/?ip=".$real_ip);
    $ip_data=json_decode($ip_data,true);
    if($ip_data['code'
    ==200){
    $diqu='黑龙江|北京|杭州'; //屏蔽的地区
    $array=explode('|',$diqu);
    foreach($array as $row){
    if(strpos($ip_data['location'],$row)!==false) {
    ecs_header("Location: http://www.xxx.net");
    }
    }
    }[/code]
    签到成功!签到时间:2022/12/2 20:35:40,每日签到,生活更精彩!