[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?