A problem in including

[b]reflesh.php[/b]

<?php session_start();

[COLOR="red"]$sessionTime=2;[/COLOR]

if (!isset($_SESSION['startTime'])){
    $_SESSION['startTime'] = time();
}
if (time()-$_SESSION['startTime'] > $sessionTime){
  $_SESSION['reflesh'] = 1;
  $_SESSION['startTime']=time();
 }

if (isset($_SESSION['reflesh']) )
{
if ($_SESSION['reflesh']==0)
{header('Location: reflesh1.php');}
}

$_SESSION['reflesh'] =0
?>

I have the code above in http://dot.kr/x-test/reflesh.php and the code below at http://dot.kr/x-test/reflesh1.php .

[b]reflesh1.php[/b]

<?php session_start();?>

<a href="reflesh.php">reflesh</a>

<?php
$_SESSION['reflesh'] =1
?>

If you reflesh the page within 2 seconds after you open reflesh.php,
It will go to reflesh1.php.

If you reflesh reflesh.php after 2 seconds,
It will stay at reflesh.php.

It works fine.

I like to the code $sessionTime=2; in other php file.
So I wrote the following code.

[b]reflshWITHinclude.php[/b]

<?php session_start();

[COLOR="red"]include "sessionTime.php";[/COLOR] 

if (!isset($_SESSION['startTime'])){
    $_SESSION['startTime'] = time();
}
if (time()-$_SESSION['startTime'] > $sessionTime){
  $_SESSION['reflesh'] = 1;
  $_SESSION['startTime']=time();
 }

if (isset($_SESSION['reflesh']) )
{
if ($_SESSION['reflesh']==0)
{header('Location: refleshWITHinclude1.php');}
}
$_SESSION['reflesh'] =0
?>

The code above in http://dot.kr/x-test/refleshWITHinclude.php and the code below in http://dot.kr/x-test/refleshWITHinclude1.php are for it.

[b]refleshWITHinclude1.php[/b]<?php session_start();?>

<a href="refleshWITHinclude.php">refleshWITHinclude</a>

<?php
$_SESSION['reflesh'] =1
?>

If you reflesh the page within 2 seconds after you open refleshWITHinclude.php,
it says “Warning: Cannot modify header information - headers already sent by (output started at http://dot.kr\x-test\sessionTime.php:8) in http://dot.kr/x-test\\refleshWITHinclude.php on line 21” instead of going to refleshWITHinclude1.php.

If you reflesh refleshWITHinclude.php after 2 seconds,
It will stay at refleshWITHinclude.php.

How can I fix the warning?

The answer is in [FPHP]header[/FPHP]

Remember that header() must be called before any actual output is sent, either by normal HTML tags, blank lines in a file, or from PHP. It is a very common error to read code with include(), or [URL=“http://php.net/manual/en/function.require.php”]require(), functions, or another file access function, and have spaces or empty lines that are output before header() is called. The same problem exists when using a single PHP/HTML file.

$sessionTime=2; will be used lots of my pages.

I like to change the sessionTime of the all pages by one change.

Is there anyway to make the reflesh page with the $sessionTime set in another page(sessionTime.php)?

Is there anyway for a redirection instead of header()?

Try fixing sessionTime.php (line 8?) so that it doesn’t start output.