基于PHP会话的Flash消息 [英] PHP Session-Based flash message

查看:82
本文介绍了基于PHP会话的Flash消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在PHP中创建基于会话的Flash消息:

I'm trying to create a Session-Based flash message in PHP:

在register.php页面中,我将会话设置如下:

In register.php page, I set the session as follow:

$_SESSION['flash'] = 'Registered';

然后,在将用户重定向到主页后,我打印了Flash消息:

Then, after redirecting user to the home page, I printed the flash message:

if (isset($_SESSION['flash'])) {
   echo $_SESSION['flash'];
   unset($_SESSION['flash']);
}

会话在两个页面中都开始. 问题是: 仅当删除取消设置功能后,我才会在主页上显示Flash消息,然后始终打印该消息.

The session is started in both pages. The problem is: I get the flash message in the home page only if I remove the unset function, and then the message is always printed.

推荐答案

我只是通过在重定向用户以逃避执行注册页面后添加退出来解决我的问题,因此在此之前不会在当前页面中取消设置会话在下一页中使用它.

I just solved my problem by adding exit after redirecting user to escape the execution of the register page, so the session won't be unset in the current page before using it in the next page.

这篇关于基于PHP会话的Flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆