PHP记录页面停留时间的方法
程序员文章站
2022-04-08 22:03:01
...
这篇文章主要介绍了PHP记录页面停留时间的方法,涉及PHP结合js针对文件与时间的相关操作技巧,需要的朋友可以参考下:
比如需要记录http://www.heimaolianmeng.com/heimaoseojishu/这个页面停留时间首先在要监控的页面添加JS如下:
log.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);
}
}
比如需要记录http://www.heimaolianmeng.com/heimaoseojishu/这个页面停留时间首先在要监控的页面添加JS如下:
log.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);
}
}
AD:真正免费,域名+虚机+企业邮箱=0元
上一篇: webpack的样式加载详解
下一篇: 像这样的sql语句,mysql编译几次