对于一个项目,我需要一个PHP中的计时器,这个计时器在第一页打开时开始(比如1.php),当我转到第二页时说停止(比如2.php)。我怎么能用PHP做到这一点?
答案 0 :(得分:2)
非常 基本示例:
1.PHP
<?php
session_start();
$_SESSION['start'] = time();
?>
2.PHP
<?php
session_start();
if(isset($_SESSION['start'])){
$timeSince = time() - $_SESSION['start'];
echo $timeSince . ' seconds since user first loaded 1.php!';
unset($_SESSION['start']); //unset the timer variable.
} else{
//didn't visit 1.php or session has expired. You could force a redirect:
header('Location: 1.php');
exit;
}
?>
值得注意的是:
答案 1 :(得分:0)
查看microtime()函数。