更好的管理会话的方法?

This is the way that I am currently managing my future user's (I'm still learning) session.

    <?php  if(isset($_SESSION['username']) && !empty($_SESSION['username'])){
        $user = $_SESSION['username'];   ?> 
<html>page for user's that are logged in here</html>

    <?php  }else { 
session_unset();
session_destroy();
?>
<html>Content for those who are not logged in goes here.  like a login form, general content and whatnot.</html>
<?php }?>

I've used this method of dealing with the session throughout the project. Most of the pages that have this will have a javascript redirect in the 'else' section that occurs if the $_SESSION['username'] is not set. The page returns to the primary index of the projects root directory. However, when it redirects there, I get this error

Notice: Undefined index: username

instead of just loading the content for a user without a session. The content that is supposed to display for user's without valid sessions has no php variables in it. So, for some reason, php is not picking up on the fact that $_SESSION['username'] is not set.

Does anybody have a better way of dealing with user sessions? Or have any suggestions or pointers to keep this error from occurring?