php - 如果父级如何重定向

发布于 2024-12-19 10:24:53 字数 370 浏览 2 评论 0原文

我的索引页面上有一个 iframe,不应在该父页面之外查看。

因此,如果没有在父页面上查看 iframe http://mysite.com/index.php 它应该重定向到 http://mysite.com/

我正在考虑类似的事情:

if ($_SERVER['REQUEST_URI'] !== 'http://mysite.com/') {
    include_once 'http://mysite.com/';
}

There is an iframe on my index page that is not suposed to be viewed outside of that parent page.

So if the iframe isnt being viewed on the parent page http://mysite.com/index.php it should be redirected to http://mysite.com/

Im thinking of something like:

if ($_SERVER['REQUEST_URI'] !== 'http://mysite.com/') {
    include_once 'http://mysite.com/';
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

颜漓半夏 2024-12-26 10:24:54
top.location.href

但这仅在两个页面(iframe 和主页)均由同一域提供服务时才有效。

if(top.location.href!=="pageyouexpect")
{
REDIRECT WHERE YOU WANT
}
top.location.href

But that will only work if both pages (the iframe and the main page) are being served from the same domain.

if(top.location.href!=="pageyouexpect")
{
REDIRECT WHERE YOU WANT
}
羁拥 2024-12-26 10:24:53

我的做法与您的方法类似:

if ($_SERVER['HTTP_HOST'] !== 'mysite.com') {
   header("Location: mysite.com");
}

如果您仅需要索引页面,那么

if ($_SERVER['HTTP_HOST'] !== 'mysite.com' && $_SERVER['REQUEST_URI']!=='index.php') {
   header("Location: mysite.com");
}

I would do it similarly to your approach:

if ($_SERVER['HTTP_HOST'] !== 'mysite.com') {
   header("Location: mysite.com");
}

if you need it for just your index page then

if ($_SERVER['HTTP_HOST'] !== 'mysite.com' && $_SERVER['REQUEST_URI']!=='index.php') {
   header("Location: mysite.com");
}
葬花如无物 2024-12-26 10:24:53

使用 header("位置:http://...")

Use header( "Location: http://..." )

情魔剑神 2024-12-26 10:24:53

Php 无法检测该页面是否是从框架请求的.. 至少没有一个足够一致的值得一提的。如果你想要一些 javascript,你可以使用:

if (top != self) {
    // you're in an iframe, or similar.
}

Php has no way of detecting whether the page was requested from a frame .. at least not one that's consistent enough to mention. If you want some javascript, you can use:

if (top != self) {
    // you're in an iframe, or similar.
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文