是否可以使用会话变量,然后直接取消设置?
例:
//====
//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)
因此,在提交表单后,如果没有错误:
目前的问题是,如果你直接取消设置会话变量; 就好像你在"if exists"部分之前取消了它.
有解决方案吗 这甚至是最好的方法吗?
非常感谢!
这两个陈述之间是否有区别:
if ($a == 'hello') { ... }
和
if ('hello' == $a) { ... }
我注意到像Wordpress这样的应用程序倾向于使用后者,而我通常使用前者.
我似乎记得刚才读了一些东西,为后者辩护,但我不记得其背后的原因.