// 处理跨域问题
header('Content-Type: text/html;charset=utf-8');
header('Access-Control-Allow-Methods:POST,GET,OPTIONS,DELETE');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');
$origin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';
// 允许的域名
$allow_origin = array(
'localhost:9527',
'其他允许跨域的域名'
);
for ($i = 0; $i < count($allow_origin); $i++) {
if (strpos($origin, $allow_origin[$i]) > 0) {
$str = 'Access-Control-Allow-Origin:' . $origin;
header($str);
}
}
网友评论