dongmao9217 2012-01-24 17:15 采纳率: 100%
浏览 67
已采纳

部分删除/销毁$ _SESSION数据? PHP

I am looking for a way to delete only certain amounts of SESSION data that is stored whilst preserving the session data associated with the user being logged on.

At the moment I am doing this by individual unset statements to the SESSION variables I want to delete.

However I was hoping there may be a more clever way to just delete a whole section of the SESSION array whilst preserving specific variables

e.g.

$_SESSION['username'];
$_SESSION['user_id'];
$_SESSION['ttl'];

The use case for this process would be:

User Logs In --> User performs task --> Once task is complete delete session data associated with task --> User is still logged in!

I had considered perhaps using a table in my Database monitoring logins, what are your opinions on that?

Thanks for your time!

  • 写回答

4条回答 默认 最新

  • doupixian1436 2012-01-24 17:24
    关注

    There is no way to delete "whole section of the SESSION array whilst preserving specific variables".Instead of that you can use two dimensional array for a task and delete that array.

    $_SESSION["task1"]["username"] = "name"
    $_SESSION["task1"]["pass"] = "pass"
    
    $_SESSION["task2"]["name"] = "name";
    

    when task1 complete delete like

      unset($_SESSION["task1"]);
    

    now $_SESSION["task2"] still exist.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类