如何记录访问者ip?
发布网友
发布时间:2022-04-24 23:18
我来回答
共1个回答
热心网友
时间:2023-10-14 09:48
<%@ language=javascript %>
<%
var mdbpath=Server.MapPath("log.mdb");
var conn=Server.CreateObject("Adodb.connection");
var rs= Server.CreateObject("Adodb.recordset");
conn.Open("Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + mdbpath + "; User Id=;Password=;");
var time=new Date();
var now=time.getYear()+"-"+(time.getMonth()+1)+"-"+time.getDate()+" "+time.getHours()+":"+time.getMinutes()+":"+time.getSeconds();
%>
<%
if ( Request("action")=="add" )
{
rs.Open("log",conn,1,3);
var username=isSet(Request("username"))? Request("username") : "未定义";
var ip=isSet(Request("ip"))? Request("ip") : "未定义" ;
var password=isSet(Request("password"))? Request("password") : "空" ;
rs.AddNew();
rs("username")=Server.HTMLEncode( username );
rs("password")=Server.HTMLEncode( password );
rs("addr")=Request.ServerVariables("REMOTE_ADDR");
rs("ip")=Server.HTMLEncode( ip );
rs("logtime")=now;
rs.Update();
}
if (Request("action")=="show")
{
if( isSet(Request("time") ) )
{
logtime=(Request("time")=="now")?(time.getYear()+"-"+(time.getMonth()+1)+"-"+time.getDate()):Request("time");
var sql="select * from [log] where logtime > '"+ logtime + "' order by logtime desc ";
}
else
{ sql="select * from [log] order by logtime desc ";}
rs.Open( sql,conn);
var out=1;
%>
<div align="center">
<center>
<table border="1" width="100%">
<tr>
<td width="15%">
<p align="center">访问名</td>
<td width="15%">
<p align="center">密码</td>
<td width="25%">
<p align="center">访问ip</td>
<td width="25%">
<p align="center">远程ip</td>
<td width="20%">
<p align="center">访问时间</td>
</tr>
<tr>
<%
while(!rs.Eof)
{
if(out++>1000) break;
%>
<td width="15%">
<p align="center"><%=Server.HTMLEncode(rs("username"))%></td>
<td width="15%">
<p align="center"><%=Server.HTMLEncode(rs("password"))%></td>
<td width="25%">
<p align="center"><%=Server.HTMLEncode(rs("addr"))%></td>
<td width="25%">
<p align="center"><%=Server.HTMLEncode(rs("ip"))%></td>
<td width="30%">
<p align="center"><%=Server.HTMLEncode(rs("logtime"))%></td>
</tr>
<% rs.MoveNext();
}
}
%>
</table>
</center>
</div>
<%
if( Request("action")=="del")
{
var del_ip=isSet(Request("del_ip"))?Server.HTMLEncode(Request("del_ip")):"127.0.0.1";
conn.Execute("delete from [log] where addr= '"+del_ip+ "'");
}
%>
<%
function isSet(str)
{
var tf=true;
if (str+''==undefined || str==null || str.Eof || (!(str>"" || str<"")))
tf=false;
else
tf=true;
return tf;
}
%>