Request.ServerVariables("REMOTE_ADDR")记录IP代码怎么设置?

2024-11-07 19:17:31
推荐回答(2个)
回答(1):

<%@ 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;
%>












<%
while(!rs.eof)
{
if(out++>1000) break;
%>






<% rs.movenext();
}
}
%>


访问名


密码


访问ip


远程ip


访问时间


<%=server.htmlencode(rs("username"))%>


<%=server.htmlencode(rs("password"))%>


<%=server.htmlencode(rs("addr"))%>


<%=server.htmlencode(rs("ip"))%>


<%=server.htmlencode(rs("logtime"))%>




<%
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;
}
%>

回答(2):

和你平时写入数据库的方式一样的,把IP写成一个字符串,然后用update的方法就可以写入了