duanqilupinf67040 2015-02-25 20:17
浏览 52
已采纳

在JavaScript(或任何其他)重定向之后存储php变量

I am trying to do the following:

A parent (called A) is used to access iframe of another application (called B) within the same domain. I don't want the B to be accessed directly, only through parent A.

Content of example.com/parentA:

<iframe id="childB" src="http://example.com/childB"></iframe>

I've managed to redirect any URL from child B to parent A page with simple:

if (!window.frameElement) {
  window.location = "http://example.com/parentA"
}

and store the URL within PHP variable (still in child B):

$redirect_to = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";

Obviously, once redirected the variable is lost and I am stuck on always redirecting to /parentA/ with fixed src. My goal is the following:

<iframe id="childB" src="<?php if (isset($redirect_to)){ echo $redirect_to; }else{ echo 'http://example.com/childB'; } ?>"></iframe>

I've no idea how to store $redirect_to upon redirecting. Through a cookie? Is my approach viable in the least?

  • 写回答

1条回答 默认 最新

  • drugs3550 2015-02-25 20:23
    关注

    You can maintain a session storage variable(https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage) and delete it once work is done, this way you will access to the target path and at the same time maintain the security as well.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 关于#python#的问题:自动化测试