沃梦达 / 编程问答 / php问题 / 正文

如何在 Drupal 6 中存储和检索自定义会话变量?

How does one store and retrieve custom session variables in Drupal 6?(如何在 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 中存储和检索自定义会话变量?

基础教程推荐