php - 如果父级如何重定向
我的索引页面上有一个 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
但这仅在两个页面(iframe 和主页)均由同一域提供服务时才有效。
But that will only work if both pages (the iframe and the main page) are being served from the same domain.
我的做法与您的方法类似:
如果您仅需要索引页面,那么
I would do it similarly to your approach:
if you need it for just your index page then
使用
header("位置:http://...")
Use
header( "Location: http://..." )
Php 无法检测该页面是否是从框架请求的.. 至少没有一个足够一致的值得一提的。如果你想要一些 javascript,你可以使用:
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: