I work for a website doing the PHP code and managing the databases. (you can check it out if you want - http://www.cashwon.com)
NOTE: if it looks like crap, the layout/graphics are NOT my department.
ANYWAY - I use a method like follows :
requirelogin.php : requires log in - goes to sign in/sign up page if the user is not logged in
<?php
session_start();
if(!isset($HTTP_SESSION_VARS['id'])) {
//if they are not sessioned, then show them the proper page
include('notsignedin.php');
exit;
}
?>
checklogin.php : just checks to see if the user is logged in. For pages where logins aren't required, but additional items/capabilites may be displayed if they are logged in.
<?php
session_start();
if(!isset($HTTP_SESSION_VARS['id'])) { $logged_in = false; } else
{
$logged_in = true;
//the next two lines are just to make accessing these
//pieces of data easier for everyone
$username = $HTTP_SESSION_VARS['name'];
$userid = $HTTP_SESSION_VARS['id'];
}
?>
These are much more simplified than the ones used on the site, but the basic idea is here.
Hope it helps.