分享

用JS实现根据IP来源分配访问地址或域名

 looline 2007-03-07
程序代码 程序代码
‘--内网用户重定向------------------
ip =  Request.ServerVariables("REMOTE_ADDR")
if (left(ip,5)="10.10") and Request.ServerVariables("HTTP_HOST")<>"10.10.3.3" then
    response.Redirect("http://10.10.3.3/")
end if
‘----------------------------------


JS输出:

程序代码 程序代码
<% ip =  Request.ServerVariables("REMOTE_ADDR")
if (left(ip,5)="10.10") and Request.ServerVariables("HTTP_HOST")<>"10.10.3.3" then
 %>
        document.write("<SCRIPT>document.location.href=‘http://10.10.3.3/v2006‘;</SCRIPT>");
<% end if %>



再结合西方亮的404智能跳转JS,就可以完美实现内网的访问用户地址控制了.。
程序代码 程序代码
<% ip =  Request.ServerVariables("REMOTE_ADDR")
if (left(ip,5)="10.10") and Request.ServerVariables("HTTP_HOST")<>"10.10.3.3" then
 %>
        document.write("<script language=‘javascript‘> 
var newdomain=‘10.10.3.3‘;                //内外用户访问地址 
var stoptime=0;                                //页面停留时间,以秒为单位 

var My_Url=document.location.href; 
godomain(); 
function godomain() 

        var str=My_Url; 
        stag=str.indexOf(‘//‘)+1;  
        str=str.substring(stag+1,str.length) 
        stag=str.indexOf(‘/‘);  
        rstr=str.substring(0,stag);  
        olddomain=rstr; 
        My_Url=My_Url.replace(olddomain,newdomain); 
        setTimeout(‘gourl()‘,stoptime*1000); 

function gourl() 
{window.location=My_Url;} 
</script>");
<% end if %>



汗,不知道哪儿出了问题,直接在document.write里面写js内容,居然不行,又试了好几个小时,换写SRC的路径就对了.
-------------------------------------------------------------------------------------------------
1:文件:ip.asp
程序代码 程序代码
<% ip =  Request.ServerVariables("REMOTE_ADDR")
if (left(ip,5)="10.10") and Request.ServerVariables("HTTP_HOST")<>"10.10.3.3" then
 %>
        document.write("<script language=javascript src=‘/v2006/ip.js‘></script>");
<% end if %>


2.文件ip.js
程序代码 程序代码
var newdomain=‘10.10.3.3‘;                //内外用户访问地址 
var stoptime=0;                                //页面停留时间,以秒为单位  
var My_Url=document.location.href; 
godomain(); 
function godomain() 

        var str=My_Url; 
        stag=str.indexOf(‘//‘)+1;  
        str=str.substring(stag+1,str.length) 
        stag=str.indexOf(‘/‘);  
        rstr=str.substring(0,stag);  
        olddomain=rstr; 
        My_Url=My_Url.replace(olddomain,newdomain); 
        setTimeout(‘gourl()‘,stoptime*1000); 

function gourl() 
{window.location=My_Url;} 



文件3:top.shtml
程序代码 程序代码
<script language="javascript" type="text/javascript" src="/v2006/ip.asp"></script>

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多