Use the attached scripts along with this text to do it all http://www.sitepoint.com/print/users-php-sessions-mysql. It is from Kevin Yank at Sitepoint.com.
I have customised it for my own needs, basically I don't want the sign-up. I also store several other session variables after a successfull login. Read his text to see where to do that.
I also include the following in my index.php for a logout button, users like to see a logout.
<?
//LOG OUT button clicked
if (isset($_POST['log_out'])) {
$_SESSION = array();
session_destroy;
echo '<script language="javascript">window.location = "http:// your logout url here "</script>';
}
?>
... html etc
<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
<input type="submit" name="log_out" value="log out" />
</form>
This is as good as anything else I have seen and better than most. The accesscontrol.php should be included in every page you want to restrict access to, users can then bookmark any protected page and will be prompted for a login whenever they use it.