在title 的onhtmltag 事件写:
var
yy,mm,dd:word;
s,img,rc:string;
i:integer;
sip:string;
allnum:integer;
begin
// 加入IP 计数
if tagstring='getalluser' then
begin
sip:=request.RemoteAddr; //浏览器地址
with cx do
begin
sql.Clear;
SQL.Add('select max(id)+1 AS NUM from ip '); //取最大IP 值
OPen;
allnum:=fields[0].asinteger;
sql.Clear;
SQL.Add('select max(iptime) as iptime from ip where ip='''+sip+''''); // 是否访问过本站
OPen;
if Isempty then
//没有访问过本站
begin
SQL.Clear;
SQL.Add('INSERT INTO IP (ID,IP ,IPTIME ,IPTYPE ) VALUES (:1,:2, CURRENT_TIMESTAMP, :3)');
Params[0].AsInteger:=allnum;
Params[1].AsString:=sip;
Params[2].asstring:=request.UserAgent;
try
ExecSQL; //写入访问时间
except
exit;
end;
end
else
begin
//访问过本站
if (now-fields[0].asdatetime)>(1/12) then
//是否两小时内访问过
begin
SQL.Clear;
SQL.Add('INSERT INTO IP (ID,IP ,IPTIME ,IPTYPE ) VALUES (:1,:2,CURRENT_TIMESTAMP, :3)');
Params[0].AsInteger:=allnum;
Params[1].asstring:=sip;
Params[2].asstring:=request.UserAgent;
try
ExecSQL;
except
exit;
end;
end;
end;
end;
ReplaceText:=''; //仅仅是计数,不返回结果
end;
if tagstring='curuser' then //显示当前五分钟内在线用户
begin
with cx do
begin
SQL.Clear;
SQL.Add(' select count(*) as num from IP');
SQL.Add(' where (CURRENT_TIMESTAMP-iptime)