Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/242.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 需要通过https加载http js和css-获取混合内容错误_Php_Proxy_File Get Contents - Fatal编程技术网

Php 需要通过https加载http js和css-获取混合内容错误

Php 需要通过https加载http js和css-获取混合内容错误,php,proxy,file-get-contents,Php,Proxy,File Get Contents,我正在尝试在https网站的iframe中加载http网站。我知道它会给我js和css的混合内容错误,所以为了解决混合内容,我使用代理,如下所示: $url = "http://www.myweb.com"; $PROXY_HOST = "47.52.24.117"; // Proxy server address $PROXY_PORT = "80"; // Proxy server port $PROXY_USER = ""; // Username $PROXY_PASS =

我正在尝试在https网站的iframe中加载http网站。我知道它会给我js和css的混合内容错误,所以为了解决混合内容,我使用代理,如下所示:

$url = "http://www.myweb.com";
$PROXY_HOST = "47.52.24.117"; // Proxy server address
$PROXY_PORT = "80";    // Proxy server port
$PROXY_USER = "";    // Username
$PROXY_PASS = "";   // Password
// Username and Password are required only if your proxy server needs basic authentication

$auth = base64_encode("$PROXY_USER:$PROXY_PASS");
stream_context_set_default(
 array(
  'http' => array(
    'method'=>"GET",
    'proxy' => "tcp://$PROXY_HOST:$PROXY_PORT",
    'request_fulluri' => true,
    'header' => "Proxy-Authorization: Basic $auth"
   // Remove the 'header' option if proxy authentication is not required
  )
 )
);
$res = file_get_contents($url);
echo $res;

但我仍然得到混合内容错误的js和css。(图像和html内容在https下加载良好)。

这主要是评论,但评论框中的空间有限

首先,您没有提到您正在使用的浏览器。MSIE可能会对一些不是混合内容的内容抛出此错误。如果您使用的是MSIE,您可以尝试使用其他浏览器,看看问题是否是Microsoft的怪癖之一,或者问题是否真的存在于您的代码中

当你说“像下面”时,我希望这不是你用来从远程站点检索内容的代码,因为你在这里硬编码了URL。我将确认这是通过前端控制器、mod_rewrite或404处理程序处理的,您没有告诉我们,您已经验证代理脚本是否正确翻译了URL/提供的内容是您所期望的,并且在测试之间清除了缓存

您是否检查过您正在下载的脚本和CSS不包含指向http://url的URL


您向我们展示的代码还有一个问题,它没有检查/传递mimetype。

我使用的是Chrome和Firefox浏览器。为了测试的目的,我把硬编码的网址放在这里,否则网址会在网站中动态加载。我还清除了浏览器缓存,并在私有浏览器中进行了测试。我还尝试了添加mimetype。js、css和img都有http://URL,但js和css在开发工具firebug中显示混合内容错误。