当前位置: 首页 > 图文教程 > 网络编程 > ASP > 根据IP地址自动判断转向分站的代码

ASP
ASP汉字转拼音,支持自定义特殊词语
终于找到了ASP下标越界的解决方法
ASP实现长文章手动分页的代码
如何节约程序开发中的时间
防sql注入代码
asp连接远程mssql数据库代码
fso检测文件、磁盘、文件夹是否存在代码
asp随机获取数据库中的记录代码
利用fso显示某一文件夹中的所有内容
利用asp获取客户端真实的IP地址
Cookies常用命令简介
将多行区域表单中的内容换成html代码
rs.open sql,conn,1,1中各参数的意义
动态图形验证码
常用的asp代码
ASP如何得到字符串的每一位字符
ASP用户登录代码
网站静态页面生成方法
fso生成有多行内容的html文件
fso向html文件追加内容

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


出处:互联网   整理: 软晨网(RuanChen.com)   发布: 2009-08-14   浏览: 58 ::
收藏到网摘: n/a

为了让客户端更快速的访问网站,通常一个大型网站会有许多分站,所以让客户端访问相应的分站,会让客户有更好的体验,这就要用到根据客户端IP地址转向不同的分站。这里面要用到IP数据库,可到网上去下载。IP数据库在此主要用途是根据得到的IP,找到此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://code.knowsky.com")
end if
if instr(UrlCity,"深圳")<>0 then 
   response.Redirect("http://moban.knowsky.com")
end if
if instr(UrlCity,"上海")<>0 then 
   response.Redirect("http://font.knowsky.com")
end if