小编ste*_*ton的帖子

使用后清除会话变量

是否可以使用会话变量,然后直接取消设置?

例:

//====
//Process Form
if ($_POST['Submit']) {
    $update = $userSettings->update($_POST);

    //If there are form errors
 if (!$update) {
        //Load the errors into an array
        $errors = $update[1];
    } else {
        //Set the session
        $_SESSION['showUpdated'] = true;

        //Redirect to this page
        header("Location: http://www.mysite.com/settings");
    }
}

//==================

if ($_SESSION['showUpdated']) {
 echo "Settings Updated";
    unset($_SESSION['showUpdated'];
}
Run Code Online (Sandbox Code Playgroud)

因此,在提交表单后,如果没有错误:

  • 设置会话以表示表单提交是可以的
  • 重新加载页面(以防止重新提交POST数据)
  • 如果设置了"showUpdated"会话变量,则显示"已更新"消息
  • 取消设置会话变量(因此我们在下次重新加载时看不到该消息)

目前的问题是,如果你直接取消设置会话变量; 就好像你在"if exists"部分之前取消了它.

有解决方案吗 这甚至是最好的方法吗?

非常感谢!

php forms session post login

12
推荐指数
2
解决办法
6万
查看次数

IF语句中值之前或之后的变量

这两个陈述之间是否有区别:

if ($a == 'hello') { ... }

if ('hello' == $a) { ... }

我注意到像Wordpress这样的应用程序倾向于使用后者,而我通常使用前者.

我似乎记得刚才读了一些东西,为后者辩护,但我不记得其背后的原因.

php if-statement operators

6
推荐指数
1
解决办法
389
查看次数

标签 统计

php ×2

forms ×1

if-statement ×1

login ×1

operators ×1

post ×1

session ×1