php多个地址跨域访问

namespace app\home\controller;

$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';


$allow_origin = [

'http://mob.vvvvvv.cc',

'http://cqqqq.cc',

'http://b.com',

];


if(in_array($origin, $allow_origin)){

header('Access-Control-Allow-Origin:'.$origin);

}

header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");

header('Access-Control-Allow-Methods: GET, POST, PUT');

把要跨域访问的网址放进$allow_origin,一般一个网站分pc端和移动端会有两个网址

你可能感兴趣的:(php多个地址跨域访问)