从所有用户全局删除 $_SESSION['layout']['action']!

发布于 2024-08-27 20:15:02 字数 513 浏览 7 评论 0原文

好的,我正在存储一个像这样的会话变量,如果设置了它,则可以更快地加载用户布局,而不是调用数据库。但由于布局可以通过管理员更改,我希望能够全局删除为所有用户设置 $_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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

盛装女皇 2024-09-03 20:15:02

好的,我正在存储一个会话变量
像这样加载用户布局

错误

我希望能够全局删除
所有会话在哪里

所有错误

它正在存储到我的数据库中

OMG“而不是调用数据库”!

这可以做到吗?谢谢

不要理会会话,不要将其用于全局设置。

Ok, I am storing a session variable
like so to load up users layouts

wrong

I'd like to be able to globally remove
all sessions where

wrong

it's being stored into my database

OMG "t instead of calling the database"!

Is this possible to do? Thanks

Leave sessions alone and don't use it for the global settings.

别想她 2024-09-03 20:15:02

如果您不想每次加载配置数据都访问数据库,可以将其缓存在生成的 .inc 文件中。请记住,PHP 只是文本 - 您可以使用 PHP 脚本生成另一个 PHP 脚本:

$fh = fopen('sitevars.inc'); // skipping error handling, since this is an example.
fwrite($fh, '<' . '?php' . "\n"); // split the <? tags in case an unbalanced ' somewhere hoses things
fwrite($fh, '$lifetheuniverse = 42;' . "\n"); // single quotes to the $ doesn't have to be escaped.
fwrite($fh, "\$layoutaction = 'slap forehead with palm';\n");
fclose($fh);

然后您只需 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:

$fh = fopen('sitevars.inc'); // skipping error handling, since this is an example.
fwrite($fh, '<' . '?php' . "\n"); // split the <? tags in case an unbalanced ' somewhere hoses things
fwrite($fh, '$lifetheuniverse = 42;' . "\n"); // single quotes to the $ doesn't have to be escaped.
fwrite($fh, "\$layoutaction = 'slap forehead with palm';\n");
fclose($fh);

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文