Making user login system secure with $_SESSION
One long line that is hard to read.

The technique looks legitimate, but I caution against reusing 'username' as the key for storing the login state.  Who knows, someday you might want to be able to persist a username even when logged out.  Or maybe a multi-page user registration form would set $_SESSION['username'] between pages.  I recommend choosing something more explicit, such as 'login_time' — and you could also use it later to help with automatic logouts after a certain time.

Note that calling header(…) does not halt the regular program flow.  Whoever calls check_session_valid() will still need to terminate further processing if the session is invalid, so your check_session_valid() should return a TRUE/FALSE value as well.  You could also throw an exception to ensure that regular program flow is impossible.