访问控制允许源源头问题

访问控制允许源源头问题

本文介绍了AMP 访问控制允许源源头问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我该如何解决下面的错误;

未能加载资源:服务器响应状态为 500(内部服务器错误)cdn.ampproject.org/v0.js:68 响应必须包含 AMP-Access-Control-Allow-Source-Origin 标头Yd @ cdn.ampproject.org/v0.js:68cdn.ampproject.org/v0.js:68 表单提交失败:错误:响应必须包含 AMP-Access-Control-Allow-Source-Origin 标头 reported

按照

解决方案

请用下面的代码试试

if(!empty($_POST)){$domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") ."://$_SERVER[HTTP_HOST]";header("内容类型:应用程序/json");header("访问控制-允许-凭据:真");header("Access-Control-Allow-Origin: ".str_replace('.', '-','https://example.com') .".cdn.ampproject.org");header("AMP-Access-Control-Allow-Source-Origin:" . $domain_url);header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");header("AMP-Redirect-To: https://example.com/thankyou.amp.html");header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");echo json_encode(array('successmsg'=>'data post'));出口;}

请确保域 url 应该是 https

https://example.com/ 替换为您想要的网址

How can I resolve the error below;

Followed all instructions at the AMP GitHub Page on CORS.

Below is a screenshot of my PHP code at the server side and error in the console of my browser;

解决方案

Please try with following code

if(!empty($_POST)){
        $domain_url = (isset($_SERVER['HTTPS']) ? "https" : "http") . "://$_SERVER[HTTP_HOST]";
        header("Content-type: application/json");
        header("Access-Control-Allow-Credentials: true");
        header("Access-Control-Allow-Origin: ". str_replace('.', '-','https://example.com') .".cdn.ampproject.org");
        header("AMP-Access-Control-Allow-Source-Origin: " . $domain_url);
        header("Access-Control-Expose-Headers: AMP-Access-Control-Allow-Source-Origin");
        header("AMP-Redirect-To: https://example.com/thankyou.amp.html");
        header("Access-Control-Expose-Headers: AMP-Redirect-To, AMP-Access-Control-Allow-Source-Origin");
        echo json_encode(array('successmsg'=>'data post'));
        exit;
}

Replace https://example.com/ to your desired url

这篇关于AMP 访问控制允许源源头问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-12 20:54