为什么iframe不适用于yahoo.com

Say*_*iss 2 html php iframe frames x-frame-options

我发现这不起作用:

<iframe src="http://www.yahoo.com"> </iframe>
Run Code Online (Sandbox Code Playgroud)

我已经阅读了这个问题,但我不明白他们的意思是添加:

<?php
header('X-Frame-Options: GOFORIT'); 
?>
Run Code Online (Sandbox Code Playgroud)

我试着将它添加到我的html文件的顶部(当然,将其更改为php文件),我的php文件变为:

<?php
header('X-Frame-Options: GOFORIT'); 
?>
<iframe src="http://www.yahoo.com"> </iframe>
Run Code Online (Sandbox Code Playgroud)

我在我的appserv(使用php 5.2.6)中运行它,它不起作用.任何人都可以解释我应该做些什么才能克服这个问题?

jml*_*nik 5

你运气不好:yahoo.com不允许你将他们的网站嵌入iframe.Facebook或其他热门网站也不是.

这种限制的原因是点击劫持.

您可以通过检查其网站的响应标头来验证这一点; 他们指定X-Frame-Options:SAMEORIGIN只有yahoo.com才能嵌入yahoo.com页面.

一些较旧的浏览器不会强制执行标题,但所有新标题都会强制执行.Afaik,没有简单的方法.

我能想到的唯一解决方案是实现代理脚本,即嵌入一个存在于服务器上的脚本,为您提取远程内容.

例如.您的iframe调用"/my-proxy.php?url= http://www.yahoo.com/ ",该脚本如下所示:

<?php

header('X-Frame-Options: SAMEORIGIN'); // don't allow other sites to use my proxy
echo file_get_contents($_GET['url']);
Run Code Online (Sandbox Code Playgroud)

你的旅费可能会改变...