如何仅在适当时显示会话变量?
我有一个PHP1页面,该页面将用户转移到PHP2页面,该页面设置了会话变量并将用户转移回PHP1页面。例如(登录表单显示错误消息) 现在,当我想在PHP1中显示该会话变量时,我尝试了以下操作:
if(isset($_SESSION['messages'])){
echo($_SESSION['messages']);
}
问题是即使用户仍设置了该变量,即使用户会刷新页面,它也会继续显示。 PS:我尝试使用Onload()和onunload()函数来取消设置,但它不起作用,但是我不确定是否犯了任何错误。
I have a php1 page that transfers the user to a php2 page which sets the session variable and transfers the user back to the php1 page. e.g.(login form displaying an error message)
Now when I wanted to display that session variable in php1 so I tried the following:
if(isset($_SESSION['messages'])){
echo($_SESSION['messages']);
}
the problem is that it will keep being displayed even if the user refreshes the page since the variable is still set.
ps: I tried to use onload() and onunload() functions to unset it but it did not work, but I'm not sure if I did any mistakes.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
显示后删除会话变量。
Remove the session variable after you show it.