0

我有以下 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>

当我在 google chrome 中打开它时,我从上面的 url 中得到了 4 个带有预期内容的帧。但在第一帧中,谁的 src 来自谷歌,我什么也没得到;只是一个空白框架。知道这里发生了什么吗?

谢谢

4

3 回答 3

4

Google 将其X-Frame-Options标头设置为SAMEORIGIN,这会禁止非 Google.com 网站嵌入其页面。大多数现代浏览器都尊重此设置。

于 2012-04-30T21:45:52.417 回答
0

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

<?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!");
#....
?>
于 2013-03-22T16:14:36.067 回答
0

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

从这里,单击控制台,然后检查是否有任何错误消息。我记得使用 Same-Origin x-frame 选项遇到了类似的问题 - 但这是针对存在身份验证问题的 GDocs。在我的情况下没有简单的解决方法,我使用了一个单独的选项卡。

该主题也可能有所帮助: 如何将 Google Docs 集合嵌入到 iframe 中?

于 2012-04-30T21:44:30.857 回答