繁体   English   中英

将HTML Frame src设置为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>

当我在谷歌浏览器中打开此文件时,我从上述网址中获得了4个包含预期内容的框架。 但是在第一帧中,谁的src是来自google的,我什么也没得到; 只是一个空白的框架。 知道这里发生了什么吗?

谢谢

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

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

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

该线程可能也有帮助: 如何将Google Docs集合嵌入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!");
#....
?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM