I am developing a theme with a separate login link. The login link opens a thickbox so people can login directly.

The problem is that after people succesfully login they are redirected to the homepage. I want them to go to the page they were looking at when they decided to log in (the referrer page). The sama issue occurs with the logout link. Users should not leave the page or at least be redirected back if they logout.

Several 'solutions' I tried did not work:
1) actions and triggers: only sets a fixed redirect page. I want the user to go back to the referrer page from which they clicked on the login link.
2) login destination module: I think this can only be used for a fixed redirect link and works only for login, not logout. I cannot test because the settings menu do not show up in my administration menu. http://drupal.org/project/login_destination

3) use drupal_get_destination. Although this seems to be able to do the trick I cannot get it to work. I now have the following code. The login link works perfectly and is fully functional. The redirect does not work, after the login users redirected to the homepage. they should be directed to the referrer page.

l(t('Login'),'user/login', array(), drupal_get_destination());
l(t('Uitloggen'), 'logout', array(), drupal_get_destination());

regards
Erik