SESSION变量显示在其定义之前

时间:2022-11-05 19:41:35

Im standing out with a issue, that the SESSION variable is "showing" before its defined..

我突出了一个问题,SESSION变量在其定义之前“显示”。

Index.php is my site, where there is a design and inside that there is a frame. Now, index.php have this:

Index.php是我的网站,有一个设计,里面有一个框架。现在,index.php有这个:

<div id='message2' onclick="closeNotice2()" style="display: none">
<? echo $_SESSION["user_message_123456"]; ?>
</div>

Inside the frame, there is a insert.php that stores data to user_message_123456.

在框架内部,有一个insert.php,用于将数据存储到user_message_123456。

Now before it has been stored, it will show undefined.. but after it has been stored, it will still show at undefined, UNTIL you refresh the page..

在它存储之前,它将显示未定义..但在存储之后,它仍将显示在undefined,UNTIL你刷新页面..

But, i want to do so, when you have stored the session, it will display it, and you will not need to refresh the page(f5).

但是,我想这样做,当你存储会话时,它会显示它,你不需要刷新页面(f5)。

I know this is causing because that you call $_SESSION variable when you are loading index.php, and its not defined unless you didnt ran insert.php, but i want to find another method/way to do this.

我知道这是因为你在加载index.php时调用$ _SESSION变量,除非你没有运行insert.php,否则它没有定义,但我想找到另一种方法/方法来执行此操作。

Any ideas how to do this? examples? show me, please!!

任何想法如何做到这一点?例子?请告诉我!

2 个解决方案

#1


0  

It doesn't sound particularly doable to do what you want done. Pages loaded after other pages can't exactly go back and change the past.

做你想做的事并不是特别可行。在其他页面之后加载的页面无法完全返回并更改过去。

If you're absolutely sure that the frame is a vital part of your approach, you'll have to use cross-frame Javascript to allow the two documents to communicate. However, it may very well be that your application flow simply needs modified to make this task unnecessary. Depending on Javascript when not necessary is unwise.

如果您完全确定框架是您的方法的重要组成部分,则必须使用跨框架Javascript来允许两个文档进行通信。但是,很可能您的应用程序流只需要修改即可完成此任务。根据Javascript,不必要是不明智的。

#2


0  

To show some new content on the outer frame without reloading it, you may use some simple JavaScript.

要在外框上显示一些新内容而不重新加载它,您可以使用一些简单的JavaScript。

Add the following script to your insert.php file, in a part where you already have written the value into the $_SESSION array:

将以下脚本添加到insert.php文件中,在已将值写入$ _SESSION数组的部分中:

<script type="text/javascript">
    var container = parent.document.getElementById('message2');
    container.innerHTML = '<?=$_SESSION["user_message_123456"]?>';
</script>

Some tips:

一些技巧:

  • This will set the contents of your <div id='message2'... to the variable's value.
  • 这会将
  • If it doesn't work, add the following line before the </script> end tag:

    如果它不起作用,请在 结束标记之前添加以下行:

    alert('Script is working');
    

    Now check if you see the message popup when insert.php loads. If not, it means the script is not being executed; move the code so it is placed either inside <head> or just before the end </body></html>

    现在检查insert.php加载时是否看到弹出消息。如果不是,则表示脚本未被执行;移动代码,使其放在内或在结束 之前

Hope this helps

希望这可以帮助

#1


0  

It doesn't sound particularly doable to do what you want done. Pages loaded after other pages can't exactly go back and change the past.

做你想做的事并不是特别可行。在其他页面之后加载的页面无法完全返回并更改过去。

If you're absolutely sure that the frame is a vital part of your approach, you'll have to use cross-frame Javascript to allow the two documents to communicate. However, it may very well be that your application flow simply needs modified to make this task unnecessary. Depending on Javascript when not necessary is unwise.

如果您完全确定框架是您的方法的重要组成部分,则必须使用跨框架Javascript来允许两个文档进行通信。但是,很可能您的应用程序流只需要修改即可完成此任务。根据Javascript,不必要是不明智的。

#2


0  

To show some new content on the outer frame without reloading it, you may use some simple JavaScript.

要在外框上显示一些新内容而不重新加载它,您可以使用一些简单的JavaScript。

Add the following script to your insert.php file, in a part where you already have written the value into the $_SESSION array:

将以下脚本添加到insert.php文件中,在已将值写入$ _SESSION数组的部分中:

<script type="text/javascript">
    var container = parent.document.getElementById('message2');
    container.innerHTML = '<?=$_SESSION["user_message_123456"]?>';
</script>

Some tips:

一些技巧:

  • This will set the contents of your <div id='message2'... to the variable's value.
  • 这会将
  • If it doesn't work, add the following line before the </script> end tag:

    如果它不起作用,请在 结束标记之前添加以下行:

    alert('Script is working');
    

    Now check if you see the message popup when insert.php loads. If not, it means the script is not being executed; move the code so it is placed either inside <head> or just before the end </body></html>

    现在检查insert.php加载时是否看到弹出消息。如果不是,则表示脚本未被执行;移动代码,使其放在内或在结束 之前

Hope this helps

希望这可以帮助