Chinaunix

标题: 做了CDN的ASP网站如何取到用户真实IP? ? [打印本页]

作者: 中网露露在此    时间: 2011-07-22 16:31
标题: 做了CDN的ASP网站如何取到用户真实IP? ?
   对原来获取用户IP的函数略作改进,即可获取用户的真实IP(默认不修改情况下是获得CDN服务器的IP)。
函数如下:
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




欢迎光临 Chinaunix (http://bbs.chinaunix.net/) Powered by Discuz! X3.2