破解图片防盗链的php代码,ASP代码

  • A+
所属分类:php笔记
许多的网站图片都加了防盗链措施,常见的新浪博客、网易相册、百度空间、QQ空间都不能外链图片,如果要先把图片保存到本地再上传,不免显得麻烦。
php版的代码比较简单:
源代码   
  1. <?php
  2. $p=$_GET['p'];
  3. $pics=file($p);
  4. for($i=0;$i< count($pics);$i++)
  5. {
  6. echo $pics[$i];
  7. }
  8. ?>

使用方法:将文件保存成i.php上传到根目录
将不能外链的图片地址改成http://你的域名p.php?p=图片地址

asp版,网上用的比较多的

源代码   
  1. <%
  2. Dim url, body, myCache
  3. url = Request.QueryString("url")
  4. Set myCache = new cache
  5. myCache.name = "picindex"&url
  6. If myCache.valid Then
  7. body = myCache.value
  8. Else
  9. body = GetWebData(url)
  10. myCache.add body,dateadd("d",1,now)
  11. End If
  12. If Err.Number = 0 Then
  13. Response.CharSet = "UTF-8"
  14. Response.ContentType = "application/octet-stream"
  15. Response.BinaryWrite body
  16. Response.Flush
  17. Else
  18. Wscript.Echo Err.Description
  19. End if
  20. '取得数据
  21. Public Function GetWebData(ByVal strUrl)
  22. Dim curlpath
  23. curlpath = Mid(strUrl,1,Instr(8,strUrl,"/"))
  24. Dim Retrieval
  25. Set Retrieval = Server.CreateObject("Microsoft.XMLHTTP")
  26. With Retrieval
  27. .Open "Get", strUrl, False,"",""
  28. .setRequestHeader "Referer", curlpath
  29. .Send
  30. GetWebData =.ResponseBody
  31. End With
  32. Set Retrieval = Nothing
  33. End Function
  34. 'cache类
  35. class Cache
  36. private obj 'cache内容
  37. private expireTime '过期时间
  38. private expireTimeName '过期时间application名
  39. private cacheName 'cache内容application名
  40. private path 'url
  41. private sub class_initialize()
  42. path=request.servervariables("url")
  43. path=left(path,instrRev(path,"/"))
  44. end sub
  45. private sub class_terminate()
  46. end sub
  47. public property get blEmpty
  48. '是否为空
  49. if isempty(obj) then
  50. blEmpty=true
  51. else
  52. blEmpty=false
  53. end if
  54. end property
  55. public property get valid
  56. '是否可用(过期)
  57. if isempty(obj) or not isDate(expireTime) then
  58. valid=false
  59. elseif CDate(expireTime)<now then
  60. valid=false
  61. else
  62. valid=true
  63. end if
  64. end property
  65. public property let name(str)
  66. '设置cache名
  67. cacheName=str & path
  68. obj=application(cacheName)
  69. expireTimeName=str & "expires" & path
  70. expireTime=application(expireTimeName)
  71. end property
  72. public property let expires(tm)
  73. '重设置过期时间
  74. expireTime=tm
  75. application.lock
  76. application(expireTimeName)=expireTime
  77. application.unlock
  78. end property
  79. public sub add(var,expire)
  80. '赋值
  81. if isempty(var) or not isDate(expire) then
  82. exit sub
  83. end if
  84. obj=var
  85. expireTime=expire
  86. application.lock
  87. application(cacheName)=obj
  88. application(expireTimeName)=expireTime
  89. application.unlock
  90. end sub
  91. public property get value
  92. '取值
  93. if isempty(obj) or not isDate(expireTime) then
  94. value=null
  95. elseif CDate(expireTime)<now then
  96. value=null
  97. else
  98. value=obj
  99. end if
  100. end property
  101. public sub makeEmpty()
  102. '释放application
  103. application.lock
  104. application(cacheName)=empty
  105. application(expireTimeName)=empty
  106. application.unlock
  107. obj=empty
  108. expireTime=empty
  109. end sub
  110. public function equal(var2)
  111. '比较
  112. if typename(obj)<>typename(var2) then
  113. equal=false
  114. elseif typename(obj)="Object" then
  115. if obj is var2 then
  116. equal=true
  117. else
  118. equal=false
  119. end if
  120. elseif typename(obj)="Variant()" then
  121. if join(obj,"^")=join(var2,"^") then
  122. equal=true
  123. else
  124. equal=false
  125. end if
  126. else
  127. if obj=var2 then
  128. equal=true
  129. else
  130. equal=false
  131. end if
  132. end if
  133. end function
  134. end class
  135. %>
  • 我的微信小程序
  • 长按二维码识别查看微信小程序
  • weinxin
  • 我的个人微信号
  • 长按识别加我个人微信号
  • weinxin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: