drupal - hook_user op load does not fire? -


To save session_id to comparing after signing in with me I have the following code in the custom module. I want to add it to user object, so I said hook_user like this:

  function mymodule_init () {global $ user; If ($ user- & gt; UID == 0 & amp;!; Isset ($ _ session [anonymous_session_id]]) {$ _SESSION ['anonymous_sean_id'] = session_id ();}} Function mymodule_user ($ op, & amp; ; $ Edit, & amp; $ account, $ category = NULL) {switch ($ op) {case 'load': $ user-> anonymous_session_id = $ _SESSION ['anonymous_session_id']; breakage; default: break; }}  

However, this is not a user object. There is a 'session' field in which $ _SESSION is a serial array of information, which means that I do not need a hook user , But Why is this code not working?

You have two issues that you are running: < / P>

  1. is not in the user object $ user in hook_user () (this is not one of the parameters): it is actually $ Account .
  2. Global $ user object $ account during the hook_user () (see ) Is not fully loaded even after modification.

Fully loaded user object, do this:

  global $ user; $ Account = user_load (array ($ user- & gt; UID));  

One thing to keep in mind is that unless you run user_save () , then added to the $ user object The information is not transferred from the hook-user ($ op = 'load') page to second place: hook-user () is loaded every time the user is loaded , Which happens at least once on the page, if you want to keep session information without using the database, then use $ _ session .


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -