WordPress Website with Login system

Okay, here is a simple example. init action loads before loading WordPress website. So we can use it to check some special conditions for allowing access to users.

You should use this in functions.php

function user_custom_redirect() {
    if ( 'something' === 'something else' ) {
        // let user view WordPress website
    } else {
        // redirect them to google.com
        // can be set to redirect back to request URL also.
        wp_redirect( 'http://www.google.com', 301 );
        exit;
    }
}
add_action( 'init', 'user_custom_redirect' );

EDIT: Session

You can also start session like this.

function start_init_session() {
    session_start();
}

add_action( 'init', 'kana_init_session', 1 );