如何重定向if父级


how to redirect if parent

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

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

我想的是:

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

我会用类似于您的方法:

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");
}

使用header( "Location: http://..." )

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

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

但只有当两个页面(iframe和主页(都来自同一个域时,这才有效。

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