在外貿網站,為了禁止同行抄襲,所以防止中國ip訪問訪問,訪問的時候有密碼提示,這樣代碼碼和大家分享下
index.asp
<!--#include file="chk.asp"-->
這是你網頁正常顯示的內容
chk.asp
<%
'[session("canRead") = "" or "OK" ] to judge it!
if Instr(getIPAddress(),"中國")>0 and session("canRead")="" then
response.Redirect("login.asp")
end if
Function leleToStr(str)
Dim stream
Set stream=Server.CreateObject("ADODB.Stream")
With stream
.Type=1
.Mode=3
.Open
.Write str
.Position = 0
.Type = 2
.Charset = "gb2312"
leleToStr = .ReadText
.Close
End With
Set stream=Nothing
End Function
'獲取IP所在地區
Function getIPAddress()
on error resume next
dim xmlhttp,url
url = " set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
'開始截取字符
dim StartStr,EndStr,html
html = leleToStr(xmlhttp.responseBody)
StartStr = Instr(html,"所在地為:")
EndStr = Instr(html,"如果該IP")
html = mid(html,StartStr,EndStr-StartStr)
'再次獲取
StartStr = Instr(html,"")
StartStr = StartStr + 6
EndStr = Instr(html,"")
html = mid(html,StartStr,EndStr-StartStr)
getIPAddress = html
if err then err.clear:html = ""
set xmlhttp = nothing
End Function
%>
login.asp
<%
if Request.ServerVariables("REQUEST_METHOD")="POST" then
if trim(request("pass"))="blueidea" then
session("canRead")="OK"
response.Redirect("index.asp")
else
response.Write("密碼錯誤,返回重試!")
response.End()
end if
end if
%>
程序打包下載
/UpFile/201211/2012110479480577.rar
調用的純真在線數據庫!