Here is an example if you want to use sessions:
My guess is probably you want to use mysql
You can use the code and include it on all your protected pages,
include('./library/login.php');
if(!$_SESSION['valid_user']){header('location: sorry.php');}
You will need also a logout.php to destroy your session, here is an example: