PHP未设置会话变量 [英] PHP Unset Session Variable
问题描述
我是一个菜鸟程序员,所以我对任何明显的错误事先表示歉意.过去一周,我花了很多时间来创建产品数据库.我也可以使用表单添加产品,查看所有添加的产品等.我正在使用通过表单输入数据创建的会话.我正在努力包括使删除产品页面正常工作,我尝试使用unset清除变量,但无法使其正常工作.
I'm a noob programmer so I apologies in advance for any obvious mistakes. I've spent the past week creating a product database kinda thing. I've got too the point where I can add products using a form, view all products added etc. I've being using sessions which are created via the form input data. I'm struggling to include get a delete product page working, I've tried using unset to clear the variable but can't get it too work.
设置会话变量的"ADD产品"页面:
ADD Product page which sets the session variable:
$_SESSION['Products'][] = $_POST; //is how i set the session on the add products page.
unset $_SESSION['Products'][]; //is how i have tried to clear the session although it does not work.
任何朝着正确方向的观点将不胜感激!
Any point in the right direction will be appreciated!
推荐答案
您可以使用以下方法取消设置会话变量:
You can unset session variable using:
-
session_unset
-释放所有会话变量(等于使用:$_SESSION = array();
) -
unset($_SESSION['Products']);
-仅取消会话变量中的产品"索引. (记住:您必须像使用函数一样使用,而不是像以前那样使用) -
session_destroy
—销毁注册到会话的所有数据
session_unset
- Frees all session variables (It is equal to using:$_SESSION = array();
)unset($_SESSION['Products']);
- Unset only Products index in session variable. (Remember: You have to use like a function, not as you used)session_destroy
— Destroys all data registered to a session
要了解使用session_unset
和session_destroy
的区别,请阅读此 SO答案.那有帮助.
To know the difference between using session_unset
and session_destroy
, read this SO answer. That helps.
这篇关于PHP未设置会话变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!