在会话中存储时间

I have a code that works just fine but I have a few questions about it. I don't understand the logic of something. The code is:

<?php
session_start();

if(!isset($_SESSION['t0'])) 
{
    $_SESSION['t0']=time();
    echo $_SESSION['t0']."if<br />"; //why this is never printed?
}
else 
{

    if(time()>=($_SESSION['t0']+3))
    {
        echo $_SESSION['t0']."else-ul";
        $culoare="rgb(".rand(0,255).",".rand(0,255).",".rand(0,255).")";
        $_SESSION['t0']=time(); 
    }

}
?>

The questions would be: 1. Why the first echo is never printed? 2. Why (time()>=($_SESSION['t0']+3)) isn't always true since $_SESSION['t0'] is updated every second because of session[t0]=time() ?

Thank you!

  1. First echo statement does get executed, but it happens only on very first time. Once you had your session started value for $_SESSION['t0'] is always set, so the if condition will always return false.

  2. time()>=($_SESSION['t0']+3) condition is true when 3 seconds has passed after execution of the code. So if you reload your page after 2 seconds it will not get executed.