- ·上一篇文章:用ASP取出HTML里面的图片地址的函数
- ·下一篇文章:asp实现同网站不同目录帮定不同域名
根据IP地址自动判断转向分站的代码
为了让客户端更快速的访问网站,通常一个大型网站会有许多分站,所以让客户端访问相应的分站,会让客户有更好的体验,这就要用到根据客户端IP地址转向不同的分站。这里面要用到IP数据库,可到网上去下载。IP数据库在此主要用途是根据得到的IP,找到此IP所在的地址。
Function 
getIpvalue(clientIP)&
#39
得到客户端的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 
"
&
#38
IpValue&
#38
"
 
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
Function 
getIpvalue(clientIP)&
#39
得到客户端的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 
"
&
#38
IpValue&
#38
"
 
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
根据IP地址自动判断转向分站的代码