Typical principles:
- Database (such as MySQL) to store usernames/passwords (preferably encrypted) and any other details you need to keep.
- Register page with fields that checks the data, if correct it adds it to the database, and forwards to the login page.
- Login page, to check login then set session data if correct, might also delete any current session data.
- Logout page, delete session data.
- Snippet to check whether the current username/password set in session data is valid. if(!$login->valid()) { header('login.php'); }
The best way to do this is typically OOP, there's lots and lots of classes available for login systems.
Dan