How do we redirect a user to the last page visited after they log in like it does for the upload page?

I know how to redirect to a certain page after login, but what about the last page there were visiting? Let's say they are trying to access a member only page...they get the login thing, but then are redirected to either their profile or whatever page is set in the login.php:

$redirect_url = $config['baseurl'] . '/' . $user_info['user_name'];

Now they have to hunt for the page they originally intended to view, which is a pain in the butt. It would be nice if they were redirected back to what they were originally doing, just like with the upload page.