php ajax 跨域请求允许多个域名

2018-2-26 晦涩sunshine PHP学习笔记

php ajax 跨域请求允许多个域名



$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
$allow_origin = array(
    'http://a.com',
    'http://b.com'
);
if(in_array($origin, $allow_origin)){
    header('Access-Control-Allow-Origin:'.$origin);
}
header("Access-Control-Allow-Credentials: true");
header('Access-Control-Allow-Headers: X-Requested-With, Content-Type');


标签: php ajax 跨域

发表评论:

Powered by emlog sitemap