php redirection

HI is there a way to redirect to the requested page if members are not logged in?

For example, someone tries to reach a page that requires them to be logged in so they are firstly directed to the login page then after successfully logging in they are taken to their initial requested page.

I Don’t know if it would work but maybe an if statement:

<?php 
 /* 
 Quick example of how to see if they're logged in or not
 Only show this login form if they're logged in */
 if(Auth::LoggedIn() == false)
 { ?>

<a href="http://www.domain.com/index.php/login">
Please Login To View This Page!

<?php
{$this->show('login_form.tpl'); }
?>

</a>

Was just a thought but probably won’t work lol

To redirect back to the index page you can use;

header('Location: '.url('/'));

You can redirect to a certain page by adding the module in the url command. For example if you want to redirect to the pilots list;

header('Location: '.url('/pilots'));

Is it possible to pass the initial requested page as a variable so once they logged it it would take them to that page?