Asp download anti-leech code

Source: Internet
Author: User
Tags servervariables

Asp download anti-leech code
First:
Finally, I made a anti-leech measure for the download system and made the following code in the header of the download page. The relevant code is as follows: Copy codeThe Code is as follows: <%
From_url = Cstr (Request. ServerVariables ("HTTP_REFERER "))
Serv_url = Cstr (Request. ServerVariables ("SERVER_NAME "))
If mid (From_url, 8, len (Serv_url) <> Serv_url and mid (From_url, 8, len (Serv_url) <> "ITstudy.cn" and mid (From_url, 8, len (Serv_url) <> "www.ITstudy.cn" then
Response. write "the software you downloaded is from the IT learning network. Please download IT directly from the homepage. Thank you <br>" 'for preventing leeching
Response. write "<a href = http://www.ITstudy.cn> IT learning network http://www.ITstudy.cn </a>" 'prevent leeching
Response. end
End if
%>

Second: Copy codeThe Code is as follows: <%
'Define the function and use ADODB. Stream to read binary data.
Function ReadBinaryFile (FileName)
Const adTypeBinary = 1
Dim BinaryStream
Set BinaryStream = CreateObject ("ADODB. Stream ")
BinaryStream. Type = adTypeBinary
BinaryStream. Open
BinaryStream. LoadFromFile FileName
ReadBinaryFile = BinaryStream. Read
End Function
Response. AddHeader "Content-Disposition", "attachment?filename=2.gif" 'file name
Response. ContentType = "image/GIF" 'setting (1)
Response. Binarywrite ReadBinaryFile (server. mappath ("2.gif") 'means you read local files to prevent
Others know that the real path is stolen.
%>

(1) The following example sets the ContentType attribute to another common value.
Text/HTML.
Image/GIF image
Image/JPEG jpg image
Application/x-cdf document
Application/wma is the music type of watermelon.
For details, refer to the Web browser document or the current HTTP specification description.
In this way, the session and cookies stored by asp and the special functions of reading the HTTP header can be used to completely implement anti-theft connection.
No cache is set. It will be better if the traffic is huge.
Third:
The simplest form is to use the Active Server Pages to defend against off-site submission, cross-site submission, anti-leech ......
Method: Request. SeverVariables ("HTTP_REFERER ")
Explanation: When someone reaches the current page through a link, HTTP_REFERER saves the user's source (lailu)
For example, this example is very simple. You can add more functions.
As shown below, you can see the file content only by logging in from http://www.ITstudy.cn first.
Source code: index. aspCopy codeThe Code is as follows: <Head> <title> asp anti-leech Protection </title> <Body>
<%
Option. Explicit
Response. Buffer = Ture
%>
<%
CheckUrl ("http://ITstudy.cn/index.jsp ")
%>
<%
Function CheckUrl (url)
Dim Where: Where = Request. SeverVariables ("HTTP_REFERER ")
If Where = url Then
Call main ()
Else
Response. write ("Sorry, you must access it from" & url! ")
End if
End Function
%>
<%
Sub main ()
Response. write ("here is the webpage content you want to display ")
End sub
%>
</Body>
</Html>

Wait is useless.
I wonder if you have any good ideas.
Another method is to determine the server and the address of the previous page.Copy codeThe Code is as follows: <%
Dim from, local
From = request. ServerVariables ("HTTP_REFERER ")
Local = request. ServerVariables ("SERVER_NAME ")
If mid (from, 8, local) <> Len (local) Then
Response. write "do not submit data from outside"
Else
Call main ()
End if
Sub main ()
'Your subject content
End sub
%>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.