会话未跟进下一个网页

I am having trouble trying to fix the session on the second page. The problem is that I am able to navigate onot the next page without having to login, which must mean that I am not using the session correctly

This is the login page:

<?php

    session_start();
    $con = mysqli_connect("localhost","root","","user");

    if ( isset($_POST['username'],$_POST['password']) ) {

        $username = mysqli_real_escape_string($con, $_POST['username']);

        $password = mysqli_real_escape_string($con, $_POST['password']);

        $select_user = "SELECT * FROM user WHERE Username = '$username' AND password ='$password'";

        $run_user = mysqli_query($con, $select_user);

        $check_user = mysqli_num_rows($run_user);

        if ( $check_user > 0 ) {

        $_SESSION['User']= $username;       

        header('location:ConnectionTest.php');

        }

        else {
            echo "wrong username/password";
        }

        mysqli_close($con);
    }

?>

This is the page the login page will navigate into

<?php

session_start();

    if ( !isset($_SESSION['User']) ) {
        header('location:login.php');
    }

    $con = new mysqli("localhost", "root", "", "schema");

    $result = $con->query("SHOW TABLES");

    while ( $row = $result->fetch_row() ) {

        $table = $row[0];

        echo '<h3>',$table,'</h3>';

        $result1 = $con->query("SELECT * FROM $table");

            if ($result1) {

                echo '<table cellpadding="0" cellspacing="0" class="db-table">';

                    $column = $con->query("SHOW COLUMNS FROM $table");

                    echo '<tr>';

                        while($row3 = $column->fetch_row()) {

                        echo '<th>'.$row3[0].'</th>';

                        } //endwhile $row3

                    echo '</tr>';

                    while($row2 = $result1->fetch_row() ) {

                    echo '<tr>';

                        foreach($row2 as $key=>$value) {

                        echo '<td>',$value,'</td>';

                        } //endforeach

                    echo '</tr>';

                    } //endwhile $row2

                echo '</table><br />';

            } //endif

    } //endwhile $row

$con->close();

?>

Try stopping the script after header(). This prevents already sent headers and thus does not disturb the session:

header(...);
exit;