How to detect devel user switch I need to detect if I'm currently browsing the site as a different user, having used the devel user switch module.

The LDAP module I have triggers some profile updates on every login, based on some server variables set from AD/SSO. But by using devel switch, it's writing MY user details, to the profile of the person I've switched to. 

I need a way of detecting it, so I can prevent the profile write.

I've had a look through the devel API here but can't see that anything is set when running as another user.

Running D7.
The Devel switch feature passes the login straight to the user module in devel_switch_user(); it doesn't give other modules the chance to intervene, and doesn't provide any context that would let you know how the login has been instigated.

I guess as a simple low-tech solution you could patch that function and set a session var before it invokes the login, something like

...
if (!$old_uid) {
  // Switch from anonymous to authorized.
  drupal_session_regenerate();
}

$_SESSION['login_from_devel_switch'] = TRUE;

$edit = array();
user_module_invoke('login', $edit, $user);
...


Then you can check for the existence of that session var wherever you need to prevent the profile from writing.