1. 论坛系统升级为Xenforo,欢迎大家测试!
    排除公告

图片防盗链

本帖由 影月如风2006-03-06 发布。版面名称:谈天说地

  1. 影月如风

    影月如风 New Member

    注册:
    2005-09-07
    帖子:
    9
    赞:
    0
    If you have a neat image or logo, and someone else decides to put it up on their site, they can simply view the HTML source code and put the fully qualified URL to the image in an IMG tag on their site. There, of course, is nothing illegal with leaching images, but it is annoying if you are the one whose server is being burdened by requests from another site. This article, written by Bart Silverstein, describes a technique to protect your image files.

    First, let's look at what your IMG tag will look like to display a "protected" image from our site (www.site1.com):


    代码:
    <IMG SRC="/images/getimage.asp?FName=whatever.jpg"> 
    The filename of the image you want to display will be whatever.jpg. Now, let's look at the getimage.asp file.



    代码:
    <% Option Explicit
    
    'Get where the request came from
    Dim strBuffer, FilePath
    strBuffer = Request.ServerVariables("HTTP_REFERER")
    strBuffer = mid(strBuffer, InStr(strBuffer,".") + 1)
    strBuffer = left(strBuffer, InStr(strBuffer, "/") - 1)
    
    'Specify the path we should be served from
    ' (This can be another web site (http://www.site2.com) or
    ' some directory where the web surfer will not expect to
    ' find your images...
    FilePath = "/HIDDENIMAGES/"
    
    'Test to see if we should serve the file or not
    If strBuffer = "site1.com" then
    
    'The Image can be served
    FilePath = FilePath + Request.QueryString("FName")
    
    Else
    
    'They are trying to leach our file!!
    FilePath = "/images/leacher.jpg"
    
    End If
    
    'Send them to the appropriate file
    Response.Redirect(FilePath)
    
    %> 
    This file uses the Request.ServerVariables collection to get the HTTP_REFERRER and then, based on the value of that variable, it determins if the user can view the file or not. (For more information on the ServerVariables collection point your browser to the ServerVariables article)

    Of course this utility will not stop users from right clicking on an image and saving the file, but it will successfully stop anyone from leaching your image files.

    Happy Programming!

    http://www.4guysfromrolla.com/webtech/110398-2.shtml
     
  2. orochi

    orochi New Member

    注册:
    2006-02-26
    帖子:
    201
    赞:
    2
  3. Tameway

    Tameway New Member

    注册:
    2005-09-06
    帖子:
    1,286
    赞:
    8
    it's no use
     
  4. 风狼

    风狼 New Member

    注册:
    2005-10-01
    帖子:
    7,452
    赞:
    25
    I不认识E文。所以。can you speak chinese?
     
  5. Tameway

    Tameway New Member

    注册:
    2005-09-06
    帖子:
    1,286
    赞:
    8
    不认识英文的直接COPY到快译去
     
  6. Fufay

    Fufay New Member

    注册:
    2006-03-08
    帖子:
    10
    赞:
    1
    试试看行不行。