一个非常简单的解决方案是使用隐藏的iframe来定期加载php网页。加载的网页记录开始时间(如果它不存在)和停止时间。当该人离开该页面时,该人员首次访问该网站的时间以及他们最后一次到达该网站的时间。在这种情况下,时间戳每3秒更新一次。
我使用文件来保存日志信息。我使用的文件名包括月 - 日 - 年ipaddress.htm
示例iframe php代码。把这个yourwebsite/yourAnalyticsiFrameCode.php:
<?php
// get the IP address of the sender
$clientIpAddress=$_SERVER['REMOTE_ADDR'];
$folder = "yourAnalyticsDataFolder";
// Combine the IP address with the current date.
$clientFileRecord=$folder."/".date('d-M-Y')." ".$clientIpAddress;
$startTimeDate = "";
// check to see if the folder to store analytics exists
if (!file_exists($folder))
{
if (!mkdir($folder))
return; // error - just bail
}
if (file_exists($clientFileRecord))
{
//read the contents of the clientFileRedord
$lines = file($clientFileRecord);
$count = 0;
// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line)
{
echo($line);
if ($count == 0)
$startTimeDate = rtrim($line);
$count++;
}
}
if ($startTimeDate == "")
$startTimeDate = date('H:i:s d-M-Y');
$endTimeDate = date('H:i:s d-M-Y');
// write the start and stop times back out to the file
$file = fopen($clientFileRecord,"w");
fwrite($file,$startTimeDate."\n".$endTimeDate);
fclose($file);
?>
JavaScript的定期刷新的iframe的主网页:
<!-- Javascript to reload the analytics code -->
<script>
window.setInterval("reloadIFrame();", 3000);
function reloadIFrame() {
document.getElementById('AnalyticsID').src = document.getElementById('AnalyticsID').src
// document.frames["AnalyticsID"].location.reload();
}
</script>
的主网页中的iframe如下所示:
<iframe id="AnalyticsID" name="AnalyticsID" src="http://yourwebsite/yourAnalyticsiFrameCode.php" width="1"
height="1" frameborder="0" style="visibility:hidden;display:none">
</iframe>
一个非常简单的方法来显示时间戳文件:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title></title>
</head>
<body>
Analytics results
<br>
<?php
$folder = "yourAnalyticsDataFolder";
$files1 = scandir($folder);
// Loop through the files
foreach ($files1 as $fn)
{
echo ($fn."<br>\n");
$lines = file($folder."/".$fn);
foreach ($lines as $line_num => $line)
{
echo(" ".$line."<br>\n");
}
echo ("<br>\n <br>");
}
?>
</body>
</html>
你得到一个结果页是这样的:
22 - 2015年3月104。 37.100.30
18时09分03秒22-MAR-2015
19时18分53秒22-MAR-2015
22-MAR-2015 142.162.20.133
18时10分06秒22-MAR-2015
18点10分21秒22-MAR-2015
也:http://stackoverflow.com/问题/ 1323375/ – Chris 2009-11-21 23:22:22
谢谢,那里有很好的信息:) – caw 2009-11-26 19:25:05