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

Ask A Question

Stats

  • Questions 494k
  • Answers 494k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If the rules are equal in specificity (in this case… May 16, 2026 at 10:55 am
  • Editorial Team
    Editorial Team added an answer You would do my_window.alert("hey") in the click event for the… May 16, 2026 at 10:54 am
  • Editorial Team
    Editorial Team added an answer You'll probably need to do a string replace on the… May 16, 2026 at 10:54 am

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code in a custom module as well as I have
I have the following XAML code as part of a custom control: <telerik:RadTreeView x:Name=treeModules>
I have a custom module I made to show featured products on the homepage.
I have the following route: {language}/{controller}.mvc/{action}/{id} Once a user has choosen the language it
I have the following code in my microcontroller project: if (newThrottle < currentThrottle) {
I have the following code; $.ajax({ url: /Home/jQueryAddComment, type: POST, dataType: json, data: json,
I'm trying to follow the custom module tutorial at http://dojotoolkit.org/book/dojo-book-0-9/part-3-programmatic-dijit-and-dojo/modules-and-namespaces/creating-your-own-modul I've got a local
I have an HTML page where I want to change Image & Link with
I have been hitting a dead end with this program. I am trying to
I am working on a Windows utility program which communicates with some custom hardware

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.