我制作了一个小网站,想用asp获取来访者的ip地址,希望高手给出代码。
我制作了一个小网站,想用asp获取来访者的ip地址,并用asp写入我的网站的数据库,asp获取访问者ip的代码如何写?希望高手说的详细点,谢谢。...
我制作了一个小网站,想用asp获取来访者的ip地址,并用asp写入我的网站的数据库,asp获取访问者ip的代码如何写?希望高手说的详细点,谢谢。
展开
4个回答
展开全部
获取访问者的IP: <%=request.ServerVariables("REMOTE_ADDR")%>
<%
dim vvv
vvv=<%=request.ServerVariables("REMOTE_ADDR")%> '把IP地址赋值给 vvv 变量
set rs=server.CreateObject("adodb.recordset") '打开数据库
rs.Open "select * from ad_ip ",conn,1,3 'ad_ip 是数据表名
rs.addnew
rs("ip_address")=vvv ' ip_address 是你要存ip地址的数据字段名
rs.Update
rs.Close
set rs=nothing
%>
<%
dim vvv
vvv=<%=request.ServerVariables("REMOTE_ADDR")%> '把IP地址赋值给 vvv 变量
set rs=server.CreateObject("adodb.recordset") '打开数据库
rs.Open "select * from ad_ip ",conn,1,3 'ad_ip 是数据表名
rs.addnew
rs("ip_address")=vvv ' ip_address 是你要存ip地址的数据字段名
rs.Update
rs.Close
set rs=nothing
%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
'通用函数:如果不能取客户端真实IP,就会取客户端的代理IP
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
直接调用就可以,
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
直接调用就可以,
追问
怎么调用?可以说的具体些吗?
追答
getIP()
就可以啊,
比如,赋值给ip就
ip=getIP()
要直接显示就
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
那你可以参照一下这个
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
''''调用演示
response.write getIP()
Private Function getIP()
Dim strIPAddr
If Request.ServerVariables("HTTP_X_FORWARDED_FOR") = "" OR InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), "unknown") > 0 Then
strIPAddr = Request.ServerVariables("REMOTE_ADDR")
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ",")-1)
ElseIf InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";") > 0 Then
strIPAddr = Mid(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), 1, InStr(Request.ServerVariables("HTTP_X_FORWARDED_FOR"), ";")-1)
Else
strIPAddr = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
End If
getIP = Trim(Mid(strIPAddr, 1, 30))
End Function
''''调用演示
response.write getIP()
追问
怎么调用?可以说的具体些吗?
追答
1,赋值给ip就
dim ip4
ip4=getIP()
2,直接显示:
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
获取访问者的IP: <%=request.ServerVariables("REMOTE_ADDR")%>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询