如果根据IP实现网址跳转,但我除了要判断IP所对应城市外,还要判断该城市所对应的URL是否为空,如果为空就跳转到特定的网页,就如下代码要怎么修改啊?: user_ip = Request.ServerVariables("REMOTE_ADDR") '取得访问者IP userip_ary=split(user_ip,".") tmp_userip=userip_ary(0)*256*256*256+userip_ary(1)*256*256+userip_ary(2)*256+userip_ary(3) '按规定转换IP为数字 '从数据库找出用户IP属于的城市 set rs=Server.CreateObject("ADODB.Recordset") sql="select * from ip where Startip<="&tmp_userip&" and Endip>="&tmp_userip&"" rs.open sql,conn,1,1 if rs.eof then response.redirect "index.asp" '如果没有该城市或是IP无法识别则转到首页,也可以指定页面 else response.redirect rs("ReUrl") '如果有转到指定页面 end if rs.close set rs=nothing
附数据表名称: Startip (相关城市的IP段信息) Endip (相关城市的IP段信息) Country (相关城市名称) ReUrl (你想要跳转的城市路径如:北京 http://bj.abc.com)
=============================================================== 动网的IP地址对照关系数据 取客户段IP地址 Function GetIP() Dim GetClientIP '如果客户端用了代理服务器,则应该用ServerVariables("HTTP_X_FORWARDED_FOR")方法 GetClientIP = Request.ServerVariables("HTTP_X_FORWARDED_FOR") If GetClientIP = "" or isnull(GetClientIP) or isempty(GetClientIP) Then '如果客户端没用代理,用Request.ServerVariables("REMOTE_ADDR")方法 GetClientIP = Request.ServerVariables("REMOTE_ADDR") End If GetIP = GetClientIP End Function 得到 DIM IP IP=GETIP() 根据IP到库中找到对应的城市 比如找到长沙就跳到相应页面