從網上來的代碼,,稍微修改了一些地方,其實用的是cache類。 。
保存代碼為,比如pic.asp
使用:http://www.xxx.com/pic.asp?url=http://www.aaaa.com/log.gif
不光是163,其實就是很多防盜連的圖片都可以這個實現。
<%
'盜鏈判斷
'IfInstr(Request.ServerVariables("http_referer"),"http://"&Request.ServerVariables("server_name")&"")=0Then
'Response.Write"非法鏈接"
'Response.End
'EndIf
Dimurl,body,myCache
url=Request.QueryString("url")
SetmyCache=newcache
myCache.name="picindex"&url
IfmyCache.validThen
body=myCache.value
Else
body=GetWebData(url)
myCache.addbody,dateadd("d",1,now)
EndIf
IfErr.Number=0Then
Response.CharSet="UTF-8"
Response.ContentType="application/octet-stream"
Response.BinaryWritebody
Response.Flush
Else
Wscript.EchoErr.Description
Endif
'取得數據
PublicFunctionGetWebData(ByValstrUrl)
Dimcurlpath
curlpath=Mid(strUrl,1,Instr(8,strUrl,"/"))
DimRetrieval
SetRetrieval=Server.CreateObject("Microsoft.XMLHTTP")
WithRetrieval
.Open"Get",strUrl,False,"",""
.setRequestHeader"Referer",curlpath
.Send
GetWebData=.ResponseBody
EndWith
SetRetrieval=Nothing
EndFunction
'cache類
classCache
privateobj'cache內容
privateexpireTime'過期時間
privateexpireTimeName'過期時間application名
privatecacheName'cache內容application名
privatepath'url
privatesubclass_initialize()
path=request.servervariables("url")
path=left(path,instrRev(path,"/"))
endsub
privatesubclass_terminate()
endsub
publicpropertygetblEmpty
'是否為空
ifisempty(obj)then
blEmpty=true
else
blEmpty=false
endif
endproperty
publicpropertygetvalid
'是否可用(過期)
ifisempty(obj)ornotisDate(expireTime)then
valid=false
elseifCDate(expireTime)<nowthen
valid=false
else
valid=true
endif