Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 970715
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:50:54+00:00 2026-05-16T02:50:54+00:00

I have the following code in a custom module to save a session_id for

  • 0

I have the following code in a custom module to save a session_id for comparison after logging in. I want to add it to the user object, so I called hook_user like so:

function mymodule_init() {
    global $user;

    if ($user->uid == 0 && !isset($_SESSION['anonymous_session_id'])) {
        $_SESSION['anonymous_session_id'] = session_id();
    }
}

function mymodule_user($op, &$edit, &$account, $category = NULL) {
    switch ($op) {
        case 'load':
            $user->anonymous_session_id = $_SESSION['anonymous_session_id'];
            break;
        default:
            break;
    }
}

However, it is not in the user object. There is a ‘session’ field that has a serialized array of $_SESSION information, which would mean I probably don’t need hook_user, but why isn’t this code working?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T02:50:55+00:00Added an answer on May 16, 2026 at 2:50 am

    There are two issues you’re running into:

    1. The user object in hook_user() isn’t in $user (it’s not one of the parameters): it’s actually in $account.
    2. The global $user object isn’t fully loaded even after modifying $account during hook_user() (See related issue).

    To get the fully loaded user object, do this:

    global $user;
    $account = user_load(array($user->uid));
    

    One thing to keep in mind is that, unless you run user_save(), information added to the $user object during hook_user($op = 'load') does not transfer from page to page: hook_user() is called every time the user is loaded, which is at least once a page. If you want to maintain session information without using the database, use $_SESSION.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code to draw a custom picker. Unfortunately when the view
I have the following code where I try to place a JLabel in a
I have the following code in my project to change mouse cursor when the
I have a WordPress website with a custom theme. I'm using custom author template
I have a field there in my report its called result. It shows something
I have a problem with a site I am redesigning and the problem is
I have a Visual Studio 2008 C# Project. Here is what works: It runs
My view controller is not responding to didRotateFromInterfaceOrientation , despite that I have added
http://lakers.sonikastudios.com/gallery/sample-gallery-post-1/ That post has several pages using the quicktag of Wordpress. This post is
I'm working on making my first Python C extension, which defines a few functions

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.