php支持多个地址跨域访问

//跨域访问的时候才会存在此字段
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : ''; 

$allow_origin = array( 
    'http://www.a.com', 
    'http://www.b.com' 
); 

if(in_array($origin, $allow_origin)){ 
    header('Access-Control-Allow-Origin:'.$origin); 
    header('Access-Control-Allow-Methods:POST, GET'); 
    header('Access-Control-Allow-Headers:x-requested-with,content-type'); 
}

 

posted on 2017-06-22 09:40  dongruiha  阅读(559)  评论(0编辑  收藏  举报

导航