Header function or redirect using PHP?

If a user goes to a page that they have not logged into(using stored session variables) what is the coding involved to redirect them to the login page?

if ($redirect)
{change this page to login}
else
{allow access to this page}

I’ve looked at the header(“location: url to be entered”) which is supposed to be the first thing on the page, then I know there is a redirect (just never seen the coding for it (I bet it is something simple)

thanks.

Sam.