【问题标题】:Setting HTML Frame src to google.com; not working将 HTML Frame src 设置为 google.com;不工作
【发布时间】:2012-05-10 13:53:23
【问题描述】:

我有以下 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 来自谷歌,我什么也没得到;只是一个空白框架。 知道这里发生了什么吗?

谢谢

【问题讨论】:

  • Google 不喜欢将他们的内容嵌入到另一个页面中?

标签: php html google-chrome


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

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

    这个帖子也可能有帮助: How can I embed a Google Docs collection in an Iframe?

    【讨论】:

      【解决方案3】:

      您可以使用 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!");
      #....
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多