PHP记录访客IP生成HTML
<?php$fp=fopen("log.htm","a");fwrite($fp,date("Y-m-dH:i:s"));fwrite($fp,"");fwrite($f...
<?php
$fp = fopen("log.htm","a ");
fwrite($fp,date("Y-m-d H:i:s"));
fwrite($fp," ");
fwrite($fp,$_SERVER[REMOTE_ADDR]);
fwrite($fp," ");
fwrite($fp,$_SERVER[HTTP_X_REWRITE_URL]);
fwrite($fp," ");
fwrite($fp,$_SERVER[HTTP_USER_AGENT]);
fwrite($fp," ");
fwrite($fp,$_SERVER["HTTP_REFERER"]);
fwrite($fp," ");
fclose($fp);
echo $fp
?>
这段代码,可以生成一个log.htm的网页,记录访客IP,时间等信息。
关键是生成出来的页面好杂乱。如何生成表格型的?
最近的访客生成的位置在页面最后面,如何把最近访客信息排到第一个位置,就是倒着排。
只记录最新100条访客信息。如果全部显示的话,页面容量会越来越大。
三个问题,请大家帮忙解答下。谢谢! 展开
$fp = fopen("log.htm","a ");
fwrite($fp,date("Y-m-d H:i:s"));
fwrite($fp," ");
fwrite($fp,$_SERVER[REMOTE_ADDR]);
fwrite($fp," ");
fwrite($fp,$_SERVER[HTTP_X_REWRITE_URL]);
fwrite($fp," ");
fwrite($fp,$_SERVER[HTTP_USER_AGENT]);
fwrite($fp," ");
fwrite($fp,$_SERVER["HTTP_REFERER"]);
fwrite($fp," ");
fclose($fp);
echo $fp
?>
这段代码,可以生成一个log.htm的网页,记录访客IP,时间等信息。
关键是生成出来的页面好杂乱。如何生成表格型的?
最近的访客生成的位置在页面最后面,如何把最近访客信息排到第一个位置,就是倒着排。
只记录最新100条访客信息。如果全部显示的话,页面容量会越来越大。
三个问题,请大家帮忙解答下。谢谢! 展开
2012-11-19 · 知道合伙人软件行家
关注
展开全部
<?php
function writeLog()
{
$fp = fopen("log.txt", "a+");
$data = array(date("Y-m-d H:i:s"),$_SERVER[REMOTE_ADDR],$_SERVER[HTTP_X_REWRITE_URL],
$_SERVER[HTTP_USER_AGENT],$_SERVER["HTTP_REFERER"]);
fputcsv($fp,$data,"\t");
fclose($fp);
}
function showHtml()
{
$fp = file("log.txt");
$table = '<table border="1">';
$count = count($fp);
if ($count<1) return;
for ($i=0;$i<100;$i++)
{
$count--;
if($count<1) break;
$line = $fp[$count];
$tr = str_replace("\t",'</td><td>',$line);
$tr = '<tr><td>'.$tr.'</tr>';
$table .= $tr;
}
$table .= '</table>';
echo $table;
}
writelog();
showHtml();
?>
function writeLog()
{
$fp = fopen("log.txt", "a+");
$data = array(date("Y-m-d H:i:s"),$_SERVER[REMOTE_ADDR],$_SERVER[HTTP_X_REWRITE_URL],
$_SERVER[HTTP_USER_AGENT],$_SERVER["HTTP_REFERER"]);
fputcsv($fp,$data,"\t");
fclose($fp);
}
function showHtml()
{
$fp = file("log.txt");
$table = '<table border="1">';
$count = count($fp);
if ($count<1) return;
for ($i=0;$i<100;$i++)
{
$count--;
if($count<1) break;
$line = $fp[$count];
$tr = str_replace("\t",'</td><td>',$line);
$tr = '<tr><td>'.$tr.'</tr>';
$table .= $tr;
}
$table .= '</table>';
echo $table;
}
writelog();
showHtml();
?>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询