The above code does the following: if the user is at the login page, the referrer is not saved for future reference (otherwise he will be redirected to the login page right after he logged in, which is, of course, not the desired effect).
In any other cases, the previously viewed page is reloaded if the user logs in with the form in the header.