Tuesday, October 6, 2009

User 0

I had a problem with Drupal once. I couldn't seem to get a message from drupal_set_message when a user registered on my site.

I added a print in the user.module:


function user_register_submit($form, &$form_state) {
...
if ($notify) {
...
}
else {
drupal_set_message(t('Your password and further instructions have been sent to your e-mail address.'));
print 'xxxxxx';
$form_state['redirect'] = '';
return;
}
}
...

}


It prints 'xxxxx';

A var_dump of the $_SESSION variable gave the status message, which drupal_set_message didn't display. So it was definitely coming at the right place!

I've uninstalled all my modules, only core remained, and used Garland as a theme.

Furthermore, I had installed a fresh Drupal installation, and there it gives me a nice status message.

Then i compared my .htaccess and Drupal's, from the fresh install. Modified mine to make them equal.

Nothing worked.

Until I found out that user 0 was missing. That was the cause. But how does that effect the $_SESSION variable in Drupal?

I posted my question on StackOverFlow and I got the solution (link to the post itself):

Drupal sessions are linked by ID number (you can see this in the session table in the database if you look) to the user. Drupal also has it's own session handling functions, and one of those is a check to see if the current session is associated with a valid user account - and for anonymous users, that is the user 0 - (it doesn't matter if multiple sessions are open per user - which is certainly what happens when so many anonymous users visit your site).

If Drupal does not find a valid user for the current session, then the session is regenerated anew - meaning the previous information is lost.

by HorusKol