单击 link. X-Frame-Options set to 'DENY'时页面重定向不会发生

问题描述 投票:2回答:2

在我的网站上的特定页面上说example.com/redirect.php我写了一个锚标签<a href="http://news.ycombinator.com/item?id=5311151">path</a>。 单击此链接时,不会加载页面。检查元素时出现此错误:

拒绝在框架中显示'https://news.ycombinator.com/item?id=5311151'因为它设置了 'X-Frame-Options'到'DENY'

谷歌搜索后我发现这是预期的行为,因为其他网站的所有者不希望在其域外的iframe中显示它的内容。 我试过这些,但所有这些都在iframe中加载。

  1. window.location.href =“https://news.ycombinator.com/item?id=5311151”;
  2. <?php header(location: https://news.ycombinator.com/item?id=5311151"); ?>
  3. window.location.replace( “https://news.ycombinator.com/item?id=5311151”);

我有两个问题:

  1. 为什么单击路径链接,新页面将加载到同一页面上的iframe(redirect.php),而不是重定向到ycombinator的页面。
  2. 如何让用户重定向到我网站之外的任何页面。

附:我正在使用灯堆。

更新:正如Serge Seredenko在评论中所建议的,我尝试使用top.location.href =“...”;这对我有用,我可以重定向页面。

另一个问题:我需要引用者的网址。使用Serge Seredenko的方法执行重定向后,我没有获得$ _SESSION ['HTTP_REFERER']的实际引用网址,而是获取内部网址。我需要实际的referer url。

我尝试使用服务器端URL重定向: <?php header(location: https://news.ycombinator.com/item?id=5311151"); ?>。 但是我收到了这个错误:'X-Frame-Options'到'SAMEORIGIN'。

如何使服务器端URL重定向并保留实际的引用URL? 非常感谢提前:)

php redirect iframe url-redirection x-frame-options
2个回答
0
投票

1)请记住,在发送任何实际输出之前,必须通过普通HTML标记,文件中的空行或PHP来调用header()。使用include或require,函数或其他文件访问函数读取代码是一个非常常见的错误,并且在调用header()之前输出空格或空行。使用单个PHP / HTML文件时存在同样的问题。 http://php.net/manual/en/function.header.php

2)试试这个:

<?php
//...some your code
print '<script type="text/javascript"> location.replace("https://google.com/"); </script>';
//...
?>

0
投票

通常当您收到此X-Frame-Options错误时,浏览器希望收到“部分”HTML页面。不是带有标签等的完整HTML页面。

这意味着当浏览器向服务器发出请求时。例如,如果两个屏幕都处于“过渡模式”(Source and destination for example in same page but in different tab like this situation)。我们得到同样的错误。

© www.soinside.com 2019 - 2024. All rights reserved.