在外貿(mào)網(wǎng)站,為了禁止同行抄襲,所以防止中國(guó)ip訪問(wèn)訪問(wèn),訪問(wèn)的時(shí)候有密碼提示,這樣代碼碼和大家分享下
index.asp
<!--#include file="chk.asp"-->
這是你網(wǎng)頁(yè)正常顯示的內(nèi)容
chk.asp
<%
'[session("canRead") = "" or "OK" ] to judge it!
if Instr(getIPAddress(),"中國(guó)")>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所在地區(qū)
Function getIPAddress()
on error resume next
dim xmlhttp,url
url = " set xmlhttp = server.CreateObject("Msxml2.XMLHTTP")
xmlhttp.open "get",url,false
xmlhttp.send
'開(kāi)始截取字符
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("密碼錯(cuò)誤,返回重試!")
response.End()
end if
end if
%>
程序打包下載
/UpFile/201211/2012110479480577.rar
調(diào)用的純真在線數(shù)據(jù)庫(kù)!