Discuz教程网

做了CDN加速的ASP网站获取用户真实IP程序

[复制链接]
authicon dly 发表于 2011-9-14 09:03:25 | 显示全部楼层 |阅读模式
  1. function checkip(checkstring)'用正则判断IP是否合法
  2. dim re1
  3. set re1=new RegExp
  4. re1.pattern="^[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}.[0-9]{1,3}$"
  5. re1.global=false
  6. re1.Ignorecase=false
  7. checkip=re1.test(checkstring)
  8. set re1=nothing
  9. end function
复制代码
  1. function get_cli_ip()'取真实IP函数,先 HTTP_CLIENT_IP 再 HTTP_X_FORWARDED_FOR 再 REMOTE_ADDR
  2. dim client_ip
  3. if checkip(Request.ServerVariables("HTTP_CLIENT_IP"))=true then
  4. get_cli_ip = checkip(Request.ServerVariables("HTTP_CLIENT_IP"))
  5. else
  6. MyArray = split(Request.ServerVariables("HTTP_X_FORWARDED_FOR"),",")
  7. if ubound(MyArray)>=0 then
  8. client_ip = trim(MyArray(0))
  9. if checkip(client_ip)=true then
  10. get_cli_ip = client_ip
  11. exit function
  12. end if
  13. end if
  14. get_cli_ip = Request.ServerVariables("REMOTE_ADDR")
  15. end if
  16. end function
复制代码




上一篇:asp 页面允许CACHE的方法
下一篇:asp中去除html中style,javascript,css代码
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2024-5-3 05:11

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表