PHP 未设置会话变量 [英] PHP Unset Session Variable

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

问题描述

我是一个菜鸟程序员,所以我提前为任何明显的错误道歉.过去一周我一直在创建一个产品数据库.我也知道我可以使用表单添加产品,查看添加的所有产品等.我一直在使用通过表单输入数据创建的会话.我正在努力让删除产品页面工作,我尝试使用 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 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:

  1. session_unset - 释放所有会话变量(它等于使用:$_SESSION = array(); 对于较旧的弃用代码)
  2. unset($_SESSION['Products']); - 在会话变量中仅取消设置产品索引.(记住:你必须像函数一样使用,而不是像你使用的那样)
  3. session_destroy — 销毁所有数据注册到会话
  1. session_unset - Frees all session variables (It is equal to using: $_SESSION = array(); for older deprecated code)
  2. unset($_SESSION['Products']); - Unset only Products index in session variable. (Remember: You have to use like a function, not as you used)
  3. session_destroy — Destroys all data registered to a session

要了解使用 session_unsetsession_destroy 之间的区别,请阅读此SO回答.这有帮助.

To know the difference between using session_unset and session_destroy, read this SO answer. That helps.

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

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