Or just do...
if (!session_id()) {
header("Location: http://www.whatever.com/");
exit();
}
no need to keep track of the time
Also why not add...
<meta http-equiv="refresh" content=300";URL=http://www.whatever.com/">
so it redirects once the session expires
content is your session time in seconds, so this will redirect you in 5 minutes if no activity.