PHP头冲突[重复]

This question already has an answer here:

Hello i make a project and i have the fallowing problem. In my index page i have a dynamic layout:

<html>
<head>
    <link rel="stylesheet" type="text/css" href="index2.css">
</head>
<body class="news">
  <header>
    <div class="nav">
      <ul>
        <li class="home"><a href="index2.php?page=welcome">Home</a></li>
        <li class="logare"><a class="active" a href="index2.php?page=admin_login">Admin</a></li>
        <li class="registration"><a href="index2.php?page=registration">Registration</a></li>
        <li class="produse"><a href="index2.php?page=produse">Produse</a></li>
      </ul>
    </div>
  </header>

  <div id="content">
<?php
 $p=$_GET['page'];

 switch($p){
        case "welcome":
          include('welcome.php');
          break;
        case "admin_login":
          include('Admin_login.php');
          break;
        case "registration":
          include('Registration.php');
          break; 
        case "produse":
          include('produse.php');
          break; 
        default:
           include('welcome.php');
          break;
 }?>
 </div>


</body>
</html>

in default and welcome case it;s redirecting me to my welcome.php page:

<?php
    session_start();

 if(!$_SESSION['email'])
    {

        header("Location: login.php");//redirect to login page to secure the welcome page without login access.
    }

    ?>

<html>
<head>

<title>
Registration
</title>
</head>

<body>
<h1>Welcome</h1><br>
<?php
    echo $_SESSION['email'];
    ?>


<h1><a href="logout.php">Logout here</a> </h1>


</body>

</html>  

Because i have a redirecting in welcome.php too ,my header is not loading from the dynamic layout.How can i repair this,but still redirecting me to login?

</div>

To avoid PHP header conflicts, I prefer to use JS redirection instead. See the below code that I have modified for you.

<?php
    session_start();

    if(!$_SESSION['email']) {
        ?>
            <script language="javascript" type="text/javascript">
                alert("User not logged in.");
                window.location = 'login.php';
            </script>
        <?php
    }      
?>

Hope this helps.