dss524049 2013-07-18 23:56
浏览 93
已采纳

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-19 00: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条)

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!