如何回显您域中的外部页面

时间:2013-11-28 12:20:19

标签: javascript php iframe proxy same-origin-policy

当我在我的HTTP页面中嵌入外部HTTPS iframe时,收到混合内容错误消息:

<iframe src="http://www.example.com/"></iframe>

要解决此限制,我想从我自己的域中回显外部页面。我该怎么做?

谢谢!

1 个答案:

答案 0 :(得分:1)

使用http(或任何其他lib)调用curl页面,并将响应打印到某些div(此div将代替{{ 1}})。

如果您想要更多指示,请附上您的iframe页面(包含PHP的人)...

proxy.php

iframe

page.html中

<?php
    $url = "http://url-of-iframe/";
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    $response = print curl_exec($ch);

    //in case that the page does not contains the <base> tag, then add it
    $base = '<base href="http://www.base-of-iframe.com/" /><!--[if IE]></base><![endif]-->';
    $response = str_replace("<head>", "<head>".$base, $response);
?>

您必须确保 <html><iframe src="https://www.yourServer.com/proxy.php"></iframe></html> 是受信任的网站!否则,他可以将恶意内容加载到您的页面中!