0

Possible Duplicate:
PHP - Cannot modify header information…

error: Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\VertrigoServ\www\alok\cookies\Time\session.php:5) in C:\Program Files\VertrigoServ\www\alok\cookies\Time\session.php on line 8

<?php
session_start();
$inactive = 10;
$session_life = time() - $_SESSION['timeout']; 
echo "$session_life";
if($session_life > $inactive){
session_destroy(); 
header("Location: logout.php");
} 
$_SESSION['timeout']=time();
?>
Community
  • 1
  • 1
Alok Ranjan
  • 31
  • 2
  • 3
  • 7

4 Answers4

0

You're trying to send headers after you've already sent out data via echo "$session_life". Headers must be sent before any other data is printed out.

Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
0

You are trying to redirect the page after you echo something to the browser. You are setting the headers of the page, which has to be the first thing that is sent back to the client. However you are already echo'ing(aka sending the body), thus not being able to set the headers.

Mike Lewis
  • 63,433
  • 20
  • 141
  • 111
0

Send the header before you output anything. (before you use the echo statement)

Scotty Waggoner
  • 3,083
  • 2
  • 26
  • 40
0

You can't echo anything before sending a header()

Kirby Todd
  • 11,254
  • 3
  • 32
  • 60