How can hidden form fields be used to improve the accuracy of tracking page request durations in PHP?

Hidden form fields can be used to pass the current timestamp from one page to another in order to calculate the duration of a page request accurately. By including a hidden form field with the current timestamp when a page is loaded, and then retrieving this timestamp on the subsequent page, the difference between the two timestamps can be calculated to determine the exact duration of the page request.

// Page 1 (sending page)
$currentTimestamp = time();
echo '<form method="post" action="page2.php">';
echo '<input type="hidden" name="timestamp" value="' . $currentTimestamp . '">';
echo '<input type="submit" value="Go to Page 2">';
echo '</form>';

// Page 2 (receiving page)
$previousTimestamp = $_POST['timestamp'];
$currentTimestamp = time();
$pageDuration = $currentTimestamp - $previousTimestamp;
echo 'Page request duration: ' . $pageDuration . ' seconds';