首页 > 解决方案 > PHP/Apache:由于内容安全政策,拒绝加载谷歌“www.gstatic.com/charts/loader.js”脚本

问题描述

我正在编写一个 PHP 视图,该视图在 Apache 的 DocumentRoot 中以单个 HTML 显示 Google 图表,它可以工作,但是当我将相同的代码放入 PHP 页面时,浏览器会抛出如下异常:

它发生在通过 src 标签调用脚本时:

Refused to load the script 'https://www.gstatic.com/charts/loader.js' 
because it violates the following Content Security Policy directive: "default-src 'self'". 
Note that 'script-src-elem' was not explicitly set, so 'default-src' is used as a fallback.

它发生在行内脚本中,代码在页面中:

Refused to execute inline script because it violates the following Content Security Policy directive: 
"default-src 'self'". Either the 'unsafe-inline' keyword, 
a hash ('sha256-gCemxHcM8ctzTMqVc2498nRLFHED+rKI4ZaErIVSSk0='), 
or a nonce ('nonce-...') 
is required to enable inline execution. 
Note also that 'script-src' was not explicitly set, so 'default-src' is used as a fallback.

我的虚拟主机如下:php743.localhost.com

我一直在为应用程序内部和 Apache 寻找解决方案,但我无法修复它。

有任何想法吗?

标签: javascriptphpapachesymfony

解决方案


推荐阅读