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 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了
  • ¥50 STM32单片机传感器读取错误
  • ¥15 (关键词-阻抗匹配,HFSS,RFID标签天线)
  • ¥15 机器人轨迹规划相关问题
  • ¥15 word样式右侧翻页键消失