you can try the following.
Once you had checked that $username and $password are correct, register $username:
session_register ('username');
(remember to write session_start() at the beginning of the script)
Then, all the protected pages should have this lines:
<?
if (session_is_registered ('username')) :
?>
--The entire page html or php stuff
<?
endif;
?>
You can also add an "else" instruction with what must be done in case the user is not logged in.
when the user logs out, you can use session_destroy();