This article gives an example of how to record the time of a page in PHP. Share to everyone for your reference, specific as follows:
First in the page to be monitored add JS as follows
<script>
var dt1 = new Date ();
Window.onbeforeunload = function () {
var dt2 = new Date ();
var ms = Dt2.gettime ()-dt1.gettime ();
var img = new Image ();
IMG.SRC = ' log.php?stay_ms= ' + ms;
}
</script>
The log.php code is as follows
<?php
$refer = ';
if (Isset ($_server[' http_referer '))
{
$refer = $_server[' Http_referer '];
}
$user _agent = ';
if (Isset ($_server[' http_user_agent '))
{
$user _agent = $_server[' http_user_agent '];
}
$ip = $_server[' remote_addr '];
if (Isset ($_get[' Stay_ms '))
{
$log = ' ['. Date (' y-m-d h:i:s '). '] ' . $ip. ' ' . $refer. ' @ ' . Number_format ($_get[' Stay_ms ')). "Ms\r\n";
File_put_contents ("Log/log_". Date ("y-m-d"). ". txt", $log, File_append);
}
if ($_server[' query_string '] = = ' | | | isset ($_get[' Day '))
} {
$day = isset ($_get[' Day '])? $_get[' Day ': Date (" Y-m-d ");
$file = "Log/log_". $day. ". txt";
if (file_exists ($file))
{
$log = file_get_contents ($file);
echo nl2br ($log);
}
}
More interested in PHP related content readers can view the site topics: "PHP Network Programming Skills Summary", "PHP basic Grammar Introductory Course", "PHP operation Office Document Skills Summary (including word,excel,access,ppt)", " PHP Date and Time usage summary, PHP Introduction to object-oriented Programming, PHP String (String) Usage summary, PHP+MYSQL database Operations Tutorial and PHP Common database operating Skills summary
I hope this article will help you with your PHP programming.