将 HTML 框架源设置为 google.com;不工作


Setting HTML Frame src to google.com; not working

我有以下PHP代码:

<?php
require_once("support.php");
$query = $_POST["search"];
$google = "http://www.google.com/search?q=" . $query;
$bing = "http://www.bing.com/search?q=" . $query;
$yahoo ="http://search.yahoo.com/search?p=" . $query;
$ask = "http://www.ask.com/web?q=" . $query;
$body= "<html><head>";
$body .= "<script src='"scripts.js'"></script>";
$body .= "</head>";
$body .= "<frameset rows='"50%,50%'" cols='"50%,50%'" >";
$body .= "<frame src='"$google'" />";
$body .= "<frame src='"$bing'" />";
$body .= "<frame src='"$yahoo'" />";
$body .= "<frame src='"$ask'" />";
$body .= "</frameset>";
$body .= "</html>";
echo $body;
?>

生成以下 html:

<html>
  <head>
      <script src="scripts.js"></script>
  </head>
  <frameset rows="50%,50%" cols="50%,50%" >
       <frame src="http://www.google.com/search?q=adf" />
       <frame src="http://www.bing.com/search?q=adf" />
       <frame src="http://search.yahoo.com/search?p=adf" />
       <frame src="http://www.ask.com/web?q=adf" />
  </frameset>
</html>

当我在谷歌浏览器中打开它时,我从上面的 URL 中得到了 4 个包含预期内容的框架。 但是在第一帧中,谁的 SRC 来自谷歌,我什么也得不到; 只是一个空白的框架。知道这里发生了什么吗?

谢谢

谷歌将他们的X-Frame-Options标题设置为SAMEORIGIN,这禁止 non-Google.com 网站嵌入他们的页面。大多数现代浏览器都遵循此设置。

您可以将开发者工具用作 chrome 扩展程序。Firebug也将做类似的工作。打 按Ctrl + Shift + J 从您的网页,Chrome 应该会弹出开发人员工具界面。

在此处,单击控制台,然后检查是否有任何错误消息。我记得在同源 x 帧选项中遇到了类似的问题 - 但这适用于存在身份验证问题的 GDocs。在我的情况下没有简单的解决方法,我使用了一个单独的选项卡。

此线程也可能有所帮助:如何在 Iframe 中嵌入 Google 文档集合?

你可以让服务器下载谷歌搜索结果页面,并使用curl将其提供给你的框架。

<?php 
function getHtml($url) {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);    
    curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);  
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0); 
    $result = curl_exec($ch);
    curl_close($ch);
    return $result;
}
$google = getHtml("https://encrypted.google.com/search?q=".$query) or die("dead!");
#....
?>