function GetIp()
dim yyrealip,yyproxy
yyrealip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
yyproxy = Request.ServerVariables("REMOTE_ADDR")
if yyrealip = "" then
GetIp = yyproxy
else
GetIp = yyrealip
end if
end function
首先创建一个数据库IP.mdb,用于记录访问者的IP地址,表IP包含字段:TITLE,IP,addtime
然后在被访问网页加如下代码:
<%
Dim zr_Conn,TITLE,IP
TITLE="某网页标题名称"
ip = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
If ip = "" Then
ip = Request.ServerVariables("REMOTE_ADDR")
end if
Set zr_Conn = Server.CreateObject("ADODB.Connection")
zr_Conn.Open "Provider = Microsoft.Jet.OLEDB.4.0;Data Source = " & Server.MapPath("IP.mdb")
zr_Conn.Execute("INSERT INTO IP (TITLE,IP,addtime) VALUES ('" & TITLE & "','" & IP & "','" & now() & "') ")
zr_Conn.Close()
Set zr_Conn=Nothing
%>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档 </title>
</head>
<body>
<%
'...数据库连接...
dim objDB,strConn
strConn="DBQ="+server.mappath("path/DB_NAME.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set objDB=server.CreateObject("adodb.connection")
objDB.open strConn
'...获取并保存IP操作
dim xip,insql
xip=request.ServerVariables("REMOTE_ADDR")
if xip="" then
xip=request.ServerVariables("REMOTE_HOST")
end if
insql="insert into 表 ([ip字段]) values ('" & xip & ")"
objDB.Execute(insql)
if err.number =0 then
response.Write "IP:" & xip & " <br>IP数据记录成功 / IP record in DB OK."
end if
%>
<!--其他操作-->
</body>
</html>
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>无标题文档</title>
</head>
<body>
<% '...数据库连接...
dim objDB,strConn
strConn="DBQ="+server.mappath("path/DB_NAME.mdb")+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set objDB=server.CreateObject("adodb.connection")
objDB.open strConn
'...获取并保存IP操作
dim xip,insql
xip=request.ServerVariables("REMOTE_ADDR")
if xip="" then
xip=request.ServerVariables("REMOTE_HOST")
end if
insql="insert into 表 ([ip字段]) values ('" & xip & ")"
objDB.Execute(insql)
if err.number =0 then
response.Write "IP:" & xip & "<br>IP数据记录成功 / IP record in DB OK."
end if
%>
<!--其他操作-->
</body>
</html>