What is wrong with this PHP code?

<?php
session_start();

if (!$_SESSION["valid_user"])
{
Header("Location:login.php");
}

include('includes/header.php');
echo "<p>User ID: " . $_SESSION["user_id"];
echo "<p>Username: " . $_SESSION["user_name"];
echo "<p>Logged in: " . date("m/d/Y", $_SESSION["login_time"]);

?>


The page keeps displaying:

Warning: session_start() [function.session-start]: Cannot send session cache limiter - headers already sent (output started at C:\...\index.php:1) in C:\...\index.php on line 1

Warning: Cannot modify header information - headers already sent by (output started at C:\...\index.php:1) in C:\...\index.php on line 5
It is the entire file.
 
if you are including this file then you will have to take out the Header if you have sent the headers in the including file.

you can also use something like this too:

if (!$_SESSION["valid_user"])
{
echo "<script language=\"javascript\" type=\"javascript\">window.location=\"login.php\"></script>
}
 
Back
Top