reg/login script, redirecting
===

i am trying to update my login script with a script, but when i login, it redirects me to the index page please can you help have a look.
this is the login script

  

      <?php
        include 'core/init.php';
        logged_in_redirect();
        if (empty($_POST) === false) {
            $username = $_POST['username'];
            $password = $_POST['password'];
            
            if (empty($username) === true || empty($password) === true) {
                $errors[] = 'You need to enter a username and password';
            } else if (user_exists($username) === false) {
                $errors[] = 'We can\'t find that username. Have you registered?';
            } else if (user_active($username) === false) {
                $errors[] = 'You haven\'t activated your account!';
            } else {
                
                if (strlen($password) > 32) {
                    $errors[] = 'Password too long';
                }
                
                $login = login($username, $password);
                if ($login === false) {
                    $errors[] = 'That username/password combination is incorrect';
                } else {
                    $_SESSION['user_id'] = $login;
                    header('Location: index.php');
                    exit();
                }
            }
        } else {
            $errors[] = 'No data received';
        }
        include 'include/header.php';
        if (empty($errors) === false) {
        ?>
            <h2>We tried to log you in, but...</h2>
        <?php
            echo output_errors($errors);
        }
        include 'include/footer.php';
        ?>


this is my index page


  

      <?php include("core/init.php");?>
        <?php include("include/header.php");?>
        <.....body>
        <?php include("include/footer.php");?>

this is my init scrip

   

     <?php
        session_start();
        //error_reporting(0);
        require 'database/connect.php';
        require 'functions/general.php';
        require 'functions/users.php';
        $current_file = explode('/', $_SERVER['SCRIPT_NAME']);
        $current_file = end($current_file);
        if (logged_in() === true) {
            $session_user_id = $_SESSION['user_id'];
            $user_data = user_data($session_user_id, 'user_id', 'username', 'password', 'first_name', 'last_name', 'email', 'password_recover', 'type', 'allow_email', 'houseno', 'addressa', 'addressb', 'addressc', 'county', 'state', 'country');
            if (user_active($user_data['username']) === false) {
                session_destroy();
                header('Location: index.php');
                exit();
            }
            if ($current_file !== 'changepassword.php' && $user_data['password_recover'] == 1) {
                header('Location: changepassword.php?force');
                exit();
            }
        }
        $errors = array();
        ?>

and my header script

   

     <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
        <html xmlns="http://www.w3.org/1999/xhtml">
        <?php include("include/head.php");?>
        <body>
        <div id="outer">
        <div id="page">
        <div id="header">
        <!--<div id="adban" style="position: absolute; left: 50%; margin-left: -150px;">
        <span style="left;"><a href="reregister.php">Click here to Register now and place your orders</a></span>
        </div>-->
        <div id="hlogo">
        <!--<span style="float:right;"><img src="img/relogo2.jpg" class="logoImage" width="96" height="96"/></span>-->
        <span style="float:right;margin:2px 2px 0 0;"><img src="img/relogo1.jpg" class="logoImage" width="96" height="96"/></span>
        </div>
        <span style="font-size:small;text-shadow: 10px 10px 1px grey;"><h1>Reacheasy<span style="font-size:small;"><?php if(isset($_SESSION['username'])){ echo $_SESSION['username'];}?></span></h1></span>
        <!--<span style="float:left;"><img src="img/rewordlogo.jpg"/></span>-->
        <ul id="nav">
        <navigation........>
        </ul>
        </div> <!--end of navigation div -->
        </div>
        <div id="navigation">
        <?php
        if(isset($_SESSION['username']))
        { ?>
        <?php include("include/menu.php");?>
        <?php }else{
        ?>
        <?php include("include/aside.php");?>
        <?php
        }
        ?>