php表单 – 2个按钮(一个用于销毁会话和重新加载页面,另一个用于
发布时间:2020-12-13 16:11:33 所属栏目:PHP教程 来源:网络整理
导读:在’selecteditems.php’页面上,我有一个这样的表格: form method="POST" name="selecteditems" action="nextpage.php"....i have some code here to display the values of the SESSION array in a table....input type="button" name="clear" value="Clea
在’selecteditems.php’页面上,我有一个这样的表格:
<form method="POST" name="selecteditems" action="nextpage.php"> ....i have some code here to display the values of the SESSION array in a table.... <input type="button" name="clear" value="Clear Session" onclick="window.location='selecteditems.php'"> <input type="submit" name="next" value="Go to Checkout"> </form> 在’selecteditems.php’页面上的表单之前,我有一些代码将数据($_REQUEST params从名为’selecteditems.php’的页面)添加到$_SESSION数组(这很好). 我的问题: 在删除会话后,获取“selecteditems.php”以重新加载并回显“session is empty”,我们将不胜感激. 解决方法
只需将您的清除会话按钮设置为提交按钮,类型为“提交”(您将其设置为type =“button”,其中跨浏览器的行为不一致无效)然后您可以将其视为正常提交流程:
if(isset($_POST['clear'])) { session_destroy(); // Or other session-unsetting logic header("Location: selecteditems.php"); // Reload your page } if(isset($_POST['next'])) { //next page logic } 您甚至可能不需要重新加载明确的会话页面.对于’会话清除消息’,您可以将逻辑添加到$_POST [‘clear’]块,或重定向到’selecteditems.php?msg =已清除’并搜索$_GET [‘msg’]并输出正确的信息,由你决定:) (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |