Hi guys.
I am having trouble understanding the below code:
<?php
if ( !isset( $_COOKIE["firstVisitTime"] ) ) {
setcookie( "firstVisitTime", time(), time() + 60 * 60 * 24 * 365, "/", "" );
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Remembering the first visit with cookies</title>
<link rel="stylesheet" type="text/css" href="common.css" />
</head>
<body>
<h2>Remembering the first visit with cookies</h2>
<?php if ( isset( $_COOKIE["firstVisitTime"] ) ) {
$elapsedTime = time() - $_COOKIE["firstVisitTime"];
$elapsedTimeMinutes = (int) ( $elapsedTime / 60 );
$elapsedTimeSeconds = $elapsedTime % 60;
?>
<p>Hi there! You first visited this page <?php echo $elapsedTimeMinutes ?>
minute<?php echo $elapsedTimeMinutes != 1 ? "s" : "" ?> and <?php echo
$elapsedTimeSeconds ?> second<?php echo $elapsedTimeSeconds != 1 ? "s" : "" ?>
ago.</p>
<?php } else { ?>
<p>It’s your first visit! Welcome!</p>
<?php }
?>
I understand most of this.
But the only thing I don't understand is how the two following lines give us the time elapsed in minutes and seconds:
$elapsedTimeMinutes = (int) ( $elapsedTime / 60 );
$elapsedTimeSeconds = $elapsedTime % 60;
To be more specific, I do not understand how:
1) dividing the elapsed time by 60 will give us the elapsed minutes?
2) and how "$elapsedTime modulus 60" gives us the seconds?
Paul.