PHP禁止外部访问API方法

具体代码:

$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;
}

0

评论0

请先

没有账号? 注册  忘记密码?

社交账号快速登录