User register and login functions are called from hook_form_alter, but user isn't logged in Background

I'm attaching the user register form, to the node create form with hook_form_alter. that way I create a node and user at once.

In order to validate and register the user, in hook_form_alter I add the relevant functions to my node form submit and validation calls.

function mymodule_form_alter form_alter(&amp;$form, &amp;$form_state, $form_id) {
   ....

    $form['#validate'][] = 'user_account_form_validate';
    $form['#submit'][] = 'user_register_submit';


Problem

The node is created and the user is created but the user isn't logged in. 


Why isn't the user logged in?


The user register and login code seems to be running ok (see below), I can only think somehow the node creation is logging the user out? I have no idea how to continue debugging this.

Debugging

Thanks to Felix, I was able to debug by logging dpm (because it doesn't appear on the page) and the code is running correctly. 

user_login_submit is called from user_register_submit

function user_login_submit($form, &amp;$form_state) {
  global $user;
  $user = user_load($form_state['uid']);
  $form_state['redirect'] = 'user/' . $user-&gt;uid;
  user_login_finalize($form_state);
}


And then user_login_finalize is called.

function user_login_finalize(&amp;$edit = array()) {
  global $user;
  watchdog('user', 'Session opened for %name.', array('%name' =&gt; $user-&gt;name));
  // Update the user table timestamp noting user has logged in.
  // This is also used to invalidate one-time login links.
  $user-&gt;login = REQUEST_TIME;
  db_update('users')
    -&gt;fields(array('login' =&gt; $user-&gt;login))
    -&gt;condition('uid', $user-&gt;uid)
    -&gt;execute();

  // Regenerate the session ID to prevent against session fixation attacks.
  // This is called before hook_user in case one of those functions fails
  // or incorrectly does a redirect which would leave the old session in place.
  drupal_session_regenerate();

  user_module_invoke('login', $edit, $user);
}


I printed out $edit and $user and $edit is $form_state and $user is the newly created user. I can't see anything going wrong. The session opening is logged by watchdog, however perhaps it's never assigned?

How else could I continue to debug this? Could drupal_session_regenerate() be logging me out?

EDIT: I switched the user_register_submit to logintoboggan_user_register_submit, which worked on my dev environment but then broke on production with the same problem as above. 

It doesn't appear to be a code problem, but something to do with the database or a setting. I dropped my production front end in front of my dev backend and it works fine, so it's some sort of database setting (which could of course effect the front end code).
If a redirect is happening after print('x') then it will be lost. dmp() should show up however I prefer using Devel Debug Log in these instances so you know if then code is running then it will output to the log.

You can use the function ddl('log message') or ddl($array) and then check the report of what has been output once your code has run.

I realise this isn't actually answering your question but may make debugging easier...