最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
详细ASP获取用户真实IP代码
时间:2010-11-03 编辑:简简单单 来源:一聚教程网
正常情况这样就能取得客户端的ip地址,但如果客户端是使用代理服务器来访问,那取到的就是代理服务器的 ip 地址,而不是真正的客户端 ip 地址,要想透过代理服务器取得客户端的真实 ip 地址,就要使用微软公司在一般asp教程技术文档中并未公布的request.servervariables("http_x_forwarded_for") 来读取,但是需要注意的是:如果客户端没有通过代理服务器来访问,那么用 request.servervariables ("http_x_forwarded_for") 取到的值将是空的。因此,如果要在程序中使用此方法,可以这样处理:
欢迎访问本网站
<% ip_address=request.servervariables ("http_x_forwarded_for")
if ip_address="" then
ip_address= request.servervariables ("remote_addr")
即:如果客户端通过代理服务器,则取 http_x_forwarded_for 的值,如果没通过代理服务器,就取 remote_addr 的值。
下面看一款真实实例
function get_cli_ip()'取真实ip函数,先 http_client_ip 再 http_x_forwarded_for 再 remote_addr
dim client_ip
if checkip(request.servervariables("http_client_ip"))=true then
get_cli_ip = checkip(request.servervariables("http_client_ip"))
else
myarray = split(request.servervariables("http_x_forwarded_for"),",")
if ubound(myarray)>=0 then
client_ip = trim(myarray(0))
if checkip(client_ip)=true then
get_cli_ip = client_ip
exit function
end if
end if
get_cli_ip = request.servervariables("remote_addr")
end if
end function
-
下一个: asp无组件文件上传实例
相关文章
- VBS 批量Ping的项目讲解 09-19
- 如何封装一个Ajax函数介绍 09-16
- ASP实现加法验证码方法 09-16
- ASP错误捕获的几种常规处理方法介绍 09-16
- ajax实现城市三级联动的代码介绍 09-16
- asp中获取日期为星期几的技巧 09-14