duanqilupinf67040 2015-02-25 12: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 12: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.

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

报告相同问题?

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

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

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

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

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

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

客服 返回
顶部