Files
ctms-yii/cors.php
T

34 lines
1.3 KiB
PHP

<?php
/**
* @Author: 嗨噜客(三亚)<fm453>
* @Date: 2025-04-10 23:19:12
* @FilePath: cors.php
* @Description:
* @Email: 393213759@qq.com
* Copyright (c) 2025 by www.hiluker.cn, All Rights Reserved.
*/
//通用的header跨域配置函数,允许各应用事先自行编写更适合的方法
if (!function_exists('setheader')) {
function setheader()
{
// 获取当前跨域域名
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
/*
@ORIGINARR 请求来源的定义字段,要求为数组
*/
defined('ORIGINARR') or define('ORIGINARR', []); //如果没有预定义,则默认防
if (in_array($origin, ORIGINARR) || in_array("*", ORIGINARR)) {
// 允许 $originarr 数组内的 域名跨域访问
header('Access-Control-Allow-Origin:' . $origin);
// 响应类型,POST,GET,PUT,等
header('Access-Control-Allow-Methods:POST,GET');
// 带 cookie 的跨域访问
header('Access-Control-Allow-Credentials: true');
// 响应头设置
header('Access-Control-Allow-Headers:x-requested-with,Content-Type,X-CSRF-Token');
}
}
}
// setheader(); //该函数必须在入口页文件中执行才能生效