dss524049 2013-07-18 15:56
浏览 94
已采纳

PHP重定向 - 突破iframe

I know this is very basic and I've never had the need before, but I want a PHP redirect to break out of any iframe (if applicable).

Is this possible?

I know that PHP sends a header to the browser, so it should be, but I can't see this anywhere.

So if I use this code then it always changes the parent and not just any iframe window:

<?php
header('Location: http://domain.com/');
?>

Of course this works, but I need it done from PHP:

<a href="page.php" target="_parent">

I'm using Symfony2 so will need to get it working in that too.

No JavaScript. PHP only (if possible).

  • 写回答

2条回答 默认 最新

  • dthh5038 2013-07-18 16:05
    关注

    You can't do it in PHP - if the browser is trying to load the page in a frame, then sending a Location header will simply load the new page in the frame too.

    If you're trying to stop others from putting your site in a frame, you'd have to use JavaScript to detect it and do the redirect, otherwise target="_top" is the right approach.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部