PHP禁止外部访问API

180it 2020-02-14 PM 2229℃ 0条
$url = $_GET['url'];
if (isset($_SERVER['HTTP_REFERER'],$url)){
    if (stripos($_SERVER['HTTP_REFERER'], $_SERVER['HTTP_HOST']) === false){
        echo json_encode(['code'=>500,"msg"=>"禁止盗用API"],JSON_UNESCAPED_UNICODE);
        exit;
    }
}else{
    echo json_encode(['code'=>500,"msg"=>"禁止直接访问"],JSON_UNESCAPED_UNICODE);
    exit;
}
支付宝打赏支付宝打赏 微信打赏微信打赏

如果文章或资源对您有帮助,欢迎打赏作者。一路走来,感谢有您!

标签: none

PHP禁止外部访问API