Website anti-collection code

Source: Internet
Author: User
Tags servervariables blank page website ip

When I was developing recently, I suddenly did not want others to collect data from my site, so I just wrote a piece of code.
<%
User_agent = request. servervariables ("http_user_agent ")
Http_reffer = request. servervariables ("http_referer ")
SERVER_NAME = request. servervariables ("SERVER_NAME ")
'Check whether the current user is a spider.
Function check (user_agent)
Allow_agent = Split ("baiduspider, Scooter, ia_archiver, googlebot, fast-webcrawler, msnbot, slurp ",",")
Check_agent = false
For agenti = lbound (allow_agent) to ubound (allow_agent)
If instr (user_agent, allow_agent (agenti)> 0 then
Check_agent = true
Exit
End if
Next
Check = check_agent
End Function
If check (user_agent) = false then
If http_reffer = "" or left (http_reffer, Len ("http: //" & SERVER_NAME) + 1) <> "http: //" & SERVER_NAME & "/" then
%>
<HTML> <body>
<Form action = ''name = checkrefer id = checkrefer method = post>
</Form>
<SCRIPT>
Document. All. checkrefer. Action = Document. url;
Document. All. checkrefer. Submit ();
</SCRIPT>
</Body> <% Response. End
End if
End if
%>
2.
The webmasters work hard to sort out the content of the added website and do not want others to take it easily. But today's collection programs are like Nb, and they always have a solution! Is it true to let them go? The answer is no. Their methods can be changed, but their website IP address will not be changed easily. We will start with this method. In order to facilitate different requirements, I have sorted out several methods for you, hope to help you! The third power collects and sorts out the information. This site only has the right to present it!
Method 1:
The best piece of code (ASP ):
<%
Dim appealnum, appealcount
Appealnum = 10' the same ip60 s request limit is 10 times
Appealcount = request. Cookies ("appealcount ")
If appealcount = "" then
Response. Cookies ("appealcount") = 1
Appealcount = 1
Response. Cookies ("appealcount"). expires = dateadd ("S", 60, now ())
Else
Response. Cookies ("appealcount") = appealcount + 1
Response. Cookies ("appealcount"). expires = dateadd ("S", 60, now ())
End if
If int (appealcount)> int (appealnum) then
Response. Write "Third Power www.3powers.cn reminds you: it is very tired to capture, take a rest! "
Response. End
End if
%>
Method 2 (ASP ):
<%
User_agent = request. servervariables ("http_user_agent ")
Http_reffer = request. servervariables ("http_referer ")
SERVER_NAME = request. servervariables ("SERVER_NAME ")
'Check whether the current user is a spider.
Function check (user_agent)
Allow_agent = Split ("baiduspider, Scooter, ia_archiver, googlebot, fast-webcrawler, msnbot, slurp ",",")
Check_agent = false
For agenti = lbound (allow_agent) to ubound (allow_agent)
If instr (user_agent, allow_agent (agenti)> 0 then
Check_agent = true
Exit
End if
Next
Check = check_agent
End Function
If check (user_agent) = false then
If http_reffer = "" or left (http_reffer, Len ("http: //" & SERVER_NAME) + 1) <> "http: //" & SERVER_NAME & "/" then
%>
<HTML> <body>
<Form action = ''name = checkrefer id = checkrefer method = post>
</Form>
<SCRIPT>
Document. All. checkrefer. Action = Document. url;
Document. All. checkrefer. Submit ();
</SCRIPT>
</Body> <% Response. End
End if
End if
%>
3.
The first anti-collection measure is to use persistence to add the session function for static pages.
Generally, only the CGI programs (Asp, PHP, and JSP) on the server have the session function, which is used to save the activity data of the user during the website (session, for a large number of static pages (HTML), only client cookies can be used to store temporary activity data. However, cookies are a very cumbersome process, it is far from as simple as session operations. Therefore, this article recommends a solution "persistence technology" in DHTML to allow users to use session functions on static pages.

Both Microsoft Internet Explorer 5 and later versions support the persistence technology, allowing us to save some data objects to the client during the current session, reduces access requests to the server, makes full use of the client computer's data processing capabilities, and improves the overall page display efficiency.
Persistence technology has the following actions available for calling:
· Savefavorite-Save the Page Status and information when the page is added to favorites
· Savehistory-Save the Page Status and information in the current session
· Savesnapshot-when the page is saved to the hard disk, the page status and information are saved.
· Userdata-Saves Page Status and information in XML format in the current session
Persistence technology breaks the tradition of using cookies and sessions, inherits some security policies of cookies, and also increases the ability to store and manage data. Each page has a user data storage capacity of 64 KB, and each site has a total storage capacity of kb.
The data format stored by persistence technology complies with XML standards. Therefore, you can use the getattribute and setattribute methods in DOM technology to access data.
The following is a typical application of persistence technology. By analyzing the stored data of persistence, the static page has the verification function.
The actual judgment process is as follows:
1. There are three objects: Visitor V, navigation page A, and Content Page C.
2. Visitor V can only see Content Page C through the link of navigation page;
3. if the visitor v accesses the Content Page C through other means (for example, through a hyperlink from another website or directly entering the URL in the IE address bar), the Content Page C will automatically prompt the copyright information, A blank page is displayed.
Specific steps:

· Add a style to the navigation page to define the persistent class, and add the storage function fnsave for authorization.
<Style>
. Userdata {behavior: URL (# default # userdata );}
</Style>
<Script language = JavaScript>
Function fnsave (){
Opersistdiv. setattribute ("bisvalid", "true ");
Opersistdiv. Save ("oxmlstore ");
}
</SCRIPT>
· Define a layer in the <body> and </body> areas of the "navigation page" to identify the persistence object
<Div class = userdata id = "opersistdiv"> </div>
· Add a statement to the hyperlink attribute of the "navigation page" to call the function fnsave:
<A hrefpolic'redhat2.htm' onmousedown = "fnsave ()">
Next, add the verification function to the "content page.
· Add a style to the "content page" to define the persistent class, and add the storage function fnload to determine the validity.
<Style>
. Userdata {behavior: URL (# default # userdata );}
</Style>
<SCRIPT>
VaR bpagevalid = false;
Function fnload (){
Opersistdiv. Load ("oxmlstore ");
If (opersistdiv. getattribute ("bisvalid "))&&
(Opersistdiv. getattribute ("bisvalid") = "true ")){
Bpass = true;
}
Else {
Bpass = false;
}
Opersistdiv. setattribute ("bisvalid", "false ");
Opersistdiv. Save ("oxmlstore ");
If (bpass = false ){
VaR serror = "the source is unknown. Please authorize the website to visit us .";
Alert (serror );
Location. href = "about: blank ";
}
} </SCRIPT>
· Modify the "content page" area as follows:
<Body onload = "fnload ()">
<Div class = userdata id = "opersistdiv"> </div>
* ** The page for inserting the above Code must be in the same folder; otherwise, an error will occur.
From the above example, we can see that the use of persistence makes normal static content pages have the session function, and general non-sensitive information can be stored on the client through session.
Multiple Static pages with the session function can be used to complete many complex tasks, such as virtual shopping cart and advanced search engine. At the same time, the transfer of some session tasks previously undertaken by the server to the client reduces the amount of data interaction and greatly reduces the burden on the server.
The third power www.3powers.cn has been collected from the Internet and has not been tested by itself. Therefore, we should use it with caution! So as not to affect search engine indexing!

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.