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>
-
is not in the user object $ userin hook_user () (this is not one of the parameters): it is actually$ Account. - Global
$ userobject$ accountduring thehook_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
Post a Comment