Bin
发布于 2024-08-22 / 18 阅读
0

PHP跨域输出JSON

$json = json_encode($arr, JSON_UNESCAPED_UNICODE);
header('Content-Type: application/json');
header('Content-Type:text/html;charset=utf-8');
$allow_origin = array('http://localhost/');
$origin = isset($_SERVER['HTTP_ORIGIN']) ? $_SERVER['HTTP_ORIGIN'] : '';
if (in_array($origin, $allow_origin)) {header('Access-Control-Allow-Origin:' . $origin);}else{
    header("Access-Control-Allow-Origin: *");
}
header("Access-Control-Allow-Credentials:true");
echo $json;