I have the following php file:
<?php
$cookielife = 10;
if( isset( $testcookie ) && !isset( $testcookieexpired ) ){
setcookie( "testcookie", $testcookie+1, time()+ 31557600 );
setcookie( "testcookieexpired", 0, time() + $cookielife );
}
if( isset($action) ){
switch( $action ){
case "setcookie":
if( !isset( $testcookie ) ){
$testcookie = 0;
setcookie( "testcookie", 0, time()+ 31557600 );
setcookie( "testcookieexpired", 0, time() + $cookielife );
}
break;
case "deletecookie":
setcookie( "testcookie" );
setcookie( "testcookieexpired" );
break;
default:
break;
}
}
print "<META HTTP-EQUIV='refresh' CONTENT='5'>\n";
print "<META HTTP-EQUIV='cache-control' CONTENT='no-cache'>\n";
print "</HEAD>\n";
?>
<BODY>
<?php
print date( "Y/m/d H:i:s", time() );
?>
<BR><BR>
<TABLE BORDER='1' WIDTH='500' CELLSPACING='0' CELLPADDING='3'>
<TR>
<TD BGCOLOR='#E0E0E0' VALIGN='top' ALIGN='left'>
<?php
if( isset( $testcookie ) ){
print " cookie 'testcookie': $testcookie\n";
} else {
print " no cookie set ...\n";
}
?>
</TD>
</TR>
</TABLE>
<BR><BR>
<A HREF=<?php print $PHP_SELF ?>?action=setcookie>Set cookie</A><BR>
<A HREF=<?php print $PHP_SELF ?>?action=deletecookie>Delete cookie</A><BR>
<A HREF=<?php print $PHP_SELF ?>?action=viewcookie>View cookie</A><BR>
</BODY>
The only thing it does is update a counter (testcookie) if the time ellapsed is higher than 10 seconds (when "testcookieexpired" expires on the client and is removed).
I have tried to simplify the code as much as possible to avoid undesired parallel effects.
Under Netscape it works fine: every 10 seconds the counter is increased by 1.
Under Microsoft's Internet Explorer (5.0...) it does update evrey 58 seconds or so.
I have tried several values for variable "cookielife" but IE seems to have its own opinion about what to do ... Netscape is working fine.
I have made searches over the internet and on this site to no luck.
I know how to get to the same result by using other way, like MySQL, but I just want to understand this thing ! I have also tried the same code using all the parameters in setcookie() and still the same.
Anyone knows what to do?
Thanks,