PHP 支持跨域

支持跨域



header('Content-Type:text/html;charset=utf-8');
$origin = ['https://www.xiaoguan.net','https://auth.xiaoguan.net','http://127.0.0.1:8408'];
$AllowOrigin = 'https://www.xiaoguan.net';
if(in_array($_SERVER["HTTP_ORIGIN"],$origin))
{
    $AllowOrigin = $_SERVER["HTTP_ORIGIN"];
}
header("Access-Control-Allow-Origin: ".$AllowOrigin );
//header('Access-Control-Allow-Origin:*'); //*标识允许所有域名跨域,不建议这么设置不安全
header('Access-Control-Allow-Methods:POST,OPTIONS');
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Allow-Headers: Content-Type,Content-Length,Accept-Encoding,X-Requested-with, Origin');