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