0

I'm printing error messages (e.g. from the login form) in my page with <?php print $messages; ?>. Nothing is showing up.

I think my problem is that the $_SESSION variable (which should contain these error messages) is empty.

I tried explicitly setting a session var in my page with $_SESSION['test'] = 'wtf';, which definitely inserted something into my drupal_sessions table:

mysql> SELECT * FROM drupal_sessions;
+-----+----------------------------+-------------+------------+-------+------------------+
| uid | sid                        | hostname    | timestamp  | cache | session          |
+-----+----------------------------+-------------+------------+-------+------------------+
|   0 | 6oq6700jo1guhe89bue0kj8jl6 | 10.16.0.132 | 1311836508 |     0 | test|s:3:"wtf";  |
+-----+----------------------------+-------------+------------+-------+------------------+

Then I added a hook_init() which did nothing except print_r($_SESSION); die;. This printed out Array ( ), i.e. an empty $_SESSION array.

So either Drupal isn't reading into the $_SESSION variable properly, or something somewhere in my site (maybe my code) is resetting the $_SESSION variable. I really need to track this down — where should I start looking? Is there an obvious way to try and debug this?

login.inc

<div id="login">
    <?php print $messages; ?>
    <?php if ($user->uid) { ?>
        <p>You are already logged in as <span id="username"><?php print $user->name; ?></span>.</p>
        <p>Would you like to <a href="/logout/">log out</a>?</p>
    <?php } else { 
        print drupal_get_form('user_login_block');
        $connector_block = (object) module_invoke('connector', 'block', 'view', 0);
        $connector_block->module = 'connector';
        $connector_block->delta = 'one_click_block';
        print theme('block', $connector_block);
        print fbconnect_render_button();
    } ?>
</div>

init hook

function mr_misc_hooks_init() {
    print_r($_SESSION);
    die;
}
4
  • Show your code.
    – Codium
    Jul 28, 2011 at 7:46
  • @drupality: I've added snippets of the login general area and of the hook where I print out the $_SESSION. Is there any particular code you need to see? I can't include everything because (1) I'm not sure what the relevant pieces of code are and I don't want to flood the issue with 100s of lines and (2) it's my clients IP and confidential. If you let me know specifically what you need me to include I'll include it.
    – George
    Jul 28, 2011 at 8:09
  • Debug tip: Try adding session_start() before printing the session global
    – Eelke
    Jul 28, 2011 at 9:37
  • @Eelke: thanks for the tip, I'll give it a try when I'm back at my desk.
    – George
    Jul 28, 2011 at 10:59

1 Answer 1

3

The database was missing user 0. I followed the instructions at devbee.com to restore that user. I'm not sure why we were missing that user, but I hope it doesn't happen again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.