I have a code that I want to check for time differences. This code below will check the the time start and time end then it will display the total time taken.
When I first load the page, the time will initialize in session. After that I will wait for a few seconds and then change the $test
variable to 1
. The if
will then executed and display Total time taken
. Then the session will be destroyed and reset everything.
However the code does not works. Time in microseconds to reflect the waited seconds is not shown??
<?php
if(!isset($_SESSION['time_start'])){
$_SESSION['time_start']=microtime(true);
}
$test ='';
if (!empty($test)){
$time_end = microtime(true);
$display = $time_end - $_SESSION['time_start'];
echo "Total time taken: $display";
session_destroy();
}
?>