从所有用户全局删除 $_SESSION['layout']['action']!
好的,我正在存储一个像这样的会话变量,如果设置了它,则可以更快地加载用户布局,而不是调用数据库。但由于布局可以通过管理员更改,我希望能够全局删除为所有用户设置 $_SESSION['layout']['action'] 的所有会话。
$_SESSION['layout']['action'] = array(a ton of indexes and mulit-dimensional arrays);
现在,我知道它被存储到我的数据库会话表中,有一列用于 session_id、last_update 和数据。所以,我的问题是如何从所有用户中删除该会话数组键 ['action']。
使用
$_SESSION = array();
session_destroy();
不起作用。 基本上,每次页面加载时都会加载 session_start() ,所以我只想从 ['layout'] 中删除所有 ['action'] 键。
这可以吗? 谢谢
Ok, I am storing a session variable like so to load up users layouts faster if it's set instead of calling the database. But since the layout can be changed via the Administrator, I'd like to be able to globally remove all sessions where $_SESSION['layout']['action'] is set for all users.
$_SESSION['layout']['action'] = array(a ton of indexes and mulit-dimensional arrays);
Now, I know it's being stored into my database sessions table, there's a column for session_id, last_update, and data. So, question I have is how to remove that session array key ['action'] from all users.
Using
$_SESSION = array();
session_destroy();
Does not work.
Basically, session_start() is being loaded on every page load, so I just want to remove all ['action'] keys from ['layout'].
Is this possible to do?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
错误
所有错误的
OMG“而不是调用数据库”!
不要理会会话,不要将其用于全局设置。
wrong
wrong
OMG "t instead of calling the database"!
Leave sessions alone and don't use it for the global settings.
如果您不想每次加载配置数据都访问数据库,可以将其缓存在生成的 .inc 文件中。请记住,PHP 只是文本 - 您可以使用 PHP 脚本生成另一个 PHP 脚本:
然后您只需
include_once('sitevars.inc');
就可以了,它是一个“全局”变量。不会弄乱会话。话虽这么说,如果您的会话存储在数据库中,很可能它们采用序列化格式。为了正确地从每个记录中剥离特定的“全局”会话变量,您必须加载每个记录,反序列化,删除变量,重新序列化,然后重新保存到数据库中。希望您不要破坏在您进行这些更新时恰好处于活动状态的某人的会话。
If you don't want to hit the database each time to load configuration data, you can cache it in a generated .inc file. Remember, PHP is just text - you can use a PHP script to generate another PHP script:
and then you just
include_once('sitevars.inc');
and boom, it's a "global" variable. No messing with sessions.That being said, if your sessions are being stored in the database, most likely they're in serialized format. To do a proper job of stripping a particular "global" session var from each, you'd have to load each record, de-serialize, delete the variable, re-serialize, and re-save into the DB. And hope you don't trash someone's session who happens to be active at the time you're doing these updates.