Home>

If the current time and the past time are acquired and the current login time is within 1 hour from the past time, "Login continued" is displayed, but the comparison method is unknown.
If i can understand, thank you.

test.php
<? php
session_start ();
$_SESSION ["nowtime"] = time ();
$_SESSION ["lasttime"] = time ();
if ($_ SESSION ["nowtime"]<$_SESSION ["lasttime"]) {
    echo "Login in progress";
} else {
    echo "Forcibly logout because session has expired", "</br>";
}

?>
Supplemental information (FW/tool version etc.)

OS: mac

php
  • Answer # 1

    Here is the logic that works.

    session_start ();
    // $_SESSION ["nowtime"] = time ();
    $nowtime = time ();

    if ($nowtime>$_SESSION ["lasttime"]) {
    echo "Login in progress";
    $_SESSION ["lasttime"] = time ();
    } else {
    echo "Forcibly logout because session has expired", "
    ";
    }

  • Answer # 2

    It's a logic problem. It's just a matter of calculating epoch-seconds for each time, calculating the difference, converting to hour, minute, second, and comparing.

  • Answer # 3

    A logic problem.
    You can update lasttime after comparing it with the current date and time. Only when you are continuing.
    Since the current date and time is only acquired every time it is accessed, it is not necessary to keep it in the session.

    When login is successful, enter the current date and time.

    However, the last pointed out "The logout word should not be entered on the screen that requires authentication" does not seem to be supported.