当前位置:首页 > ASP教程 > 应用技巧

asp 根据IP地址自动判断转向分站的代码

function getipvalue(clientip)'得到客户端的ip转换成长整型,返回值getipvalue
on error resume next
dim strip, array_ip
strip=0
array_ip = split(clientip,".")
if ubound(array_ip)<>3 then
getipvalue=0
exit function
end if
for i=0 to 3
strip=strip+(cint(array_ip(i))*(256^(3-i)))
next
getipvalue=strip
if err then getipvalue=0
end function
clientip=request.servervariables("remote_host")
ipvalue=getipvalue(clientip)
strsql="select top 1 city from [ipaddress] where "&ipvalue&"
between ip1 and ip2"
set rsip=conn.execute(strsql)
if rsip.bof and rsip.eof then
urlcity="未知"
else
urlcity=rsip.fields.item("city").value
end if
if instr(urlcity,"广州")<>0 then
response.redirect("http://www.jb51.net")
end if
if instr(urlcity,"深圳")<>0 then
response.redirect("http://img.jb51.net")
end if
if instr(urlcity,"上海")<>0 then
response.redirect("http://xiazai.jb51.net")
end if
所用到的ip数据库可以去网上down一个回来

【说明】本文章由站长整理发布,文章内容不代表本站观点,如文中有侵权行为,请与本站客服联系(QQ:)!