If you want to logout the user if they try to load a page when they've been inactive for too long, you should put this code at the top of every php file (before ANY other html tags):
if( $_SESSION['last_activity'] < time()-$_SESSION['expire_time'] ) { //have we expired?
//redirect to logout.php
header('Location: http://yoursite.com/logout.php'); //change yoursite.com to the name of you site!!
} else{ //if we haven't expired:
$_SESSION['last_activity'] = time(); //this was the moment of last activity.
}
Also, put this code at the top of the page where you land when you've successfully logged in:
$_SESSION['logged_in'] = true; //set you've logged in
$_SESSION['last_activity'] = time(); //your last activity was now, having logged in.
$_SESSION['expire_time'] = 3*60*60; //expire time in seconds: three hours (you must change this)
On that page you don't have to include the checking code I gave you first.
By the way, don't forget to add tags correctly!