一个朋友单位的网站(动易+动网),现在需要把论坛限制为指定IP访问而主站不限制,动网后台只有限制IP访问,而整个站点又是使用的共同用户API接口,因为是租用的虚拟空间,所以只能修改代码。下面为代码,需要的朋友自己复制。。。
'=======================
'判断来路分析,IP限定
'PowerBy Person01
Dim HttpUrl
HttpUrl=request.ServerVariables("SCRIPT_NAME")
'判断是否为论坛登录 其他不判断
IF UCase(Left(HttpURL,5))="/BBS/" And Ucase(HttpUrl)<>"/BBS/DV_DPO.ASP" Then
Dim Guest_IP,Allow_IP
Allow_IP="61.177.145.250|58.214.243.142|"
Dim Ip_N '定义IP数
Guest_IP = Request.ServerVariables("HTTP_X_FORWARDED_FOR")
IF Trim(Guest_IP) = "" then Guest_IP=Request.ServerVariables("REMOTE_ADDR")
Allow_IP=Split(Allow_IP,"|")
Ip_N=Ubound(Allow_IP)
Dim ip_i
Dim AllowVisit '定义是否允许访问 True |False
AllowVisit=False
For ip_i=0 to Ip_N
IF Trim(Guest_IP)=Trim(Allow_IP(ip_i)) Then AllowVisit=True
Next
IF AllowVisit=False Then
Response.Write("<script>")
Response.Write "alert('对不起,你无权访问!\n\n 请联系管理员!');"
Response.Write "window.close();"
Response.Write "</script>"
Response.End()
End IF
End IF
'======================
整个代码加在BBS/Conn.asp文件里面 就可以了