Redirecting user after logging in

You should look into $_SERVER['REQUEST_URI'] and e.g. store that in a hidden input field, so that after the successful login you can retrieve the original wanted target and redirect the user there