How does one store and retrieve custom session variables in Drupal 6?(如何在 Drupal 6 中存储和检索自定义会话变量?)
问题描述
Drupal 使用自定义会话处理程序来改变熟悉的......:
Drupal employs a custom session handler that changes the familiar...:
$_SESSION['foo'] = 'bar';
echo $_SESSION['foo'];
...行为.foo"的上述会话变量不会在页面之间保持不变.
...behavior. The above session variable of "foo" would not persist from page to page.
Drupal.com 上的许多评论和论坛条目都提出了 Drupal 出于性能原因和服务器集群支持使用自定义会话处理程序的问题.但是,我没有找到回答这个问题的具体例子——需要在 Drupal 中跨页面管理自己的会话变量,并且不想诉诸 cookie?这是你的方法......"
Many comments and forum entries at Drupal.com raise the issue that Drupal uses a custom session handler for performance reasons and server clustering support. However, I'm failing to find specific examples answering the question - "Need to manage your own session variables across pages in Drupal and don't want to resort to cookies? Here's how you do it..."
有人有这方面的经验吗?我的用法不会在外部 Drupal 页面内,而是在模板页面本身内.这是针对匿名用户,而不是登录用户.在这种情况下,$_SESSION 行为符合预期.
Does anyone have experience with this? My usage would NOT be within external Drupal pages but within template pages themselves. This is for an anonymous user, not a logged in one. $_SESSION behavior is as expected in that case.
推荐答案
好的,这就是答案 - $_SESSION 按预期适用于经过身份验证的用户和匿名用户 - 如果没有其他问题!
Ok, here's the answer - $_SESSION works for authenticated users as well as anonymous users as expected - if there are no other problems!
我发现我有以下问题;我的 Drupal用户"表(或在我的情况下为drupal_users")缺少一个 UID 为零(0")的用户.
I discovered that I had the following problem; my Drupal "users" table (or in my case "drupal_users") was missing a user with a UID of zero ("0").
Drupal 使用 UID 0 通过其自定义会话处理程序管理数据库中的会话.如果该用户不存在于表中(默认情况下应该存在),则 Drupal 无法将会话信息附加到匿名用户.
Drupal uses UID 0 to manage sessions in a database via its custom session handler. If that user doesn't exist in the table (it should be there by default installation), then Drupal cannot attach session information to the anonymous user.
这篇关于如何在 Drupal 6 中存储和检索自定义会话变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:如何在 Drupal 6 中存储和检索自定义会话变量?
基础教程推荐
- 如何在 XAMPP 上启用 mysqli? 2021-01-01
- 找不到类“AppHttpControllersDB",我也无法使用新模型 2022-01-01
- PHP 守护进程/worker 环境 2022-01-01
- 使用 PDO 转义列名 2021-01-01
- 如何在 Symfony 和 Doctrine 中实现多对多和一对多? 2022-01-01
- HTTP 与 FTP 上传 2021-01-01
- Doctrine 2 - 在多对多关系中记录更改 2022-01-01
- 在 yii2 中迁移时出现异常“找不到驱动程序" 2022-01-01
- 在 CakePHP 2.0 中使用 Html Helper 时未定义的变量 2021-01-01
- phpmyadmin 错误“#1062 - 密钥 1 的重复条目‘1’" 2022-01-01