Use ASP to establish a self-moving friendship link system

zhaozj2021-02-11  231

If you have your own website, is it true to exchange friendship with others? Each time you add another person with a manual method, have you ever thought about having an automatic friendship link system that automatically registers the website information and produces a friendship link page? If the answers to these two questions are "Yes", then, please come with me, you will soon be able to pay for it.

An automatic friendship link system should have two functions: First, you can collect and store website information; another point is to automatically generate web pages based on stored information. To achieve these two functions, it is clear that only HTML languages ​​is not enough, and must be programmed with CGI or ASP by means of other methods.

At present, foreign service providers offer ready-made CGI programs, with the ability to generate friendship links, which can certainly meet the basic requirements above, but there are at least two disadvantages: one is slow, the CGI program is not very efficient High, coupled to the foreign site, the final speed can be imagined. Another point is lack of flexibility, others' CGI programs are dead, and users do not have much almost room, so they cannot create personality pages.

The use of ASP (Active Server Pages) technology can make up for the above shortcomings. The ASP code not only has sufficient flexibility, but also executes faster than the CGI program, so ASP is a suitable choice for website owners.

First, use ASP to implement an automatic friend love link simple principle.

1. Information collection of friendship sites

In order to collect various information of the friendship site (including name, website name, address, etc.), we only need to use standard HTML FORM technology. That is, a form is placed in the page, where a number of text boxes and a "submit" button are placed, the text box is entered for the user input information, and the form of the form is set to the name of the information processing page, namely the name of the ASP file (in the following example) AutoLink.asp, the method of data transmission is set to POST.

2, the preservation of friendship website information

When the AutoLink.asp file is executed, you first use the REQUEST object's FORM attribute to read each parameter; then create an ADO (Active Data Object) object with the CreateObject method of the Server object, and set the corresponding DNS according to the type, location, name, etc. according to the type of database. After using the OPEN method of the ADO object to establish a database connection; after the connection is established, use a standard SQL statement to add a record to the database (see the following code below the SQL statement). This enables the purpose of saving information.

3, the generation of friendship link page

In order to read the database, you first use the SQL statement to create a recordset RS, then read each field content with the Field property of the RS, and generate a standard HTML statement according to the value of the field.

Second, instance

Here is a specific example.

First, we need to create a database to store all the information about all friendship websites. In this case, we build a simple database AutoLink.mdb with Access, which contains only a table AutoLink, the structure of the table is as follows:

Field Name Data Type Field Length Equivalence Field No Field Description Name Character Type 20 Yes Web Site Name Address Character Type 60 Yes Web Site Address Logoaddress Character Site 60 YES Website Identifier Icon Description Character 120 Yes Website Short Introduction

Next, we need to create two pages: AutoLink.htm and AutoLink.asp.

AutoLink.htm is a standard HTML page that collects information from other websites, which is as follows (for the saving version, the code is saved all modified statements and data integrity check statements):

Auto Link System - Please enter your website information </ Title></p> <p></ hEAD></p> <p><form method = "post" action = "autolink.asp"></p> <p><p> Website Name: <input type = "text" name = "name"> </ p></p> <p><p> Website address: <Input type = "text" name = "address"> </ p></p> <p><p> icon Address: <Input Type = "text" name = "logoaddress"> </ p></p> <p><P> Site Description: <textarea rows = "2" name = "description"> </ textarea> </ p></p> <p><p> <input type = "submit" value = "Fillted, submit" Name = "Submit"> </ P></p> <p></ form></p> <p></ body></p> <p></ html></p> <p>The above code establishes a form (form) containing three single line text boxes, a multi-line text box, and a commit button, which is responsible for receiving the user's input (including the name, address, icon, and description), when the user presses " When the "button is submitted, the form uses the information entered by the user to transfer to the AutoLink.ASP page. Because it is a pure HTML page, we can use visual tools such as FrontPage 98 to generate these codes very easy to use visualization tools such as FrontPage 98.</p> <p>The code of the AutoLink.asp page is as follows (the same omitted the modified statement):</p> <p><% @ Language = VBScript%></p> <p><html></p> <p><HEAD></p> <p><meta name = "generator" content = "Microsoft FrontPage 3.0"></p> <p><title> My friendship link </ Title></p> <p></ hEAD></p> <p><body></p> <p><%</p> <p>Name = Request.form ("name")</p> <p>Address = Request.form ("Address")</p> <p>Logoaddress = Request.form ("Logoaddress")</p> <p>Description = Request.form ("description")</p> <p>'Establish a database connection</p> <p>Set conn = server.createObject ("adoDb.connection")</p> <p>Mydsn = "driver = {Microsoft Access Driver (* .mdb)};" MYDSN = MYDSN & "DBQ =" & Server.MAppath ("AutoLink")</p> <p>Conn.open mydsn</p> <p>'Add a record</p> <p>Sqlstring = "INSERT INTO AutoLink (Name, Address, Logoaddress, Description) VALUES ("</p> <p>Sqlstring = SQLSTRING & "'" & name & ",'" & address & ", '" & logoaddress & ",'" & description & ")"</p> <p>Conn.execute Sqlstring</p> <p>'Open record set</p> <p>Sqlstring = "Select * from autolink"</p> <p>SET RS = conn.execute (sqlstring)</p> <p>%></p> <p><table border = "1" width = "72%" Cellpadding = "2"></p> <p><tr></p> <p><td width = "27%"> Website name </ td></p> <p><td width = "73%"> website icon and link </ td></p> <p></ TR></p> <p><% do while not rs.eof%></p> <p><tr></p> <p><TD Width = "27%"> <% = rs ("name")%> </ td></p> <p><TD Width = "73%"></p> <p><a href="<%=rs ("address"") "></p> <p><img src = "<% = rs (" logoaddress ")%>" alt = "<% = rs (" description ")%>> </a> </ td></p> <p></ TR></p> <p><%</p> <p>rs.movenext</p> <p>loop</p> <p>%></p> <p></ TABLE></p> <p>'Close connection</p> <p><%</p> <p>SET RS = Nothing</p> <p>Conn.close</p> <p>Set conn = Nothing</p> <p>%></p> <p></ body></p> <p></ html></p> <p>Upload the above two files and database files to the server, open AutoLink.htm with the browser, the screen as shown above.</p> <p>After completing it, press the "Submit" button, appear on the right picture, indicating that the data has been properly recorded and generated the correct HTML page.</p> <p>For examples of this article, the reader can apply it in practice only to be slightly modified.</p></div><div class="text-center mt-3 text-grey"> 转载请注明原文地址:https://www.9cbs.com/read-4123.html</div><div class="plugin d-flex justify-content-center mt-3"></div><hr><div class="row"><div class="col-lg-12 text-muted mt-2"><i class="icon-tags mr-2"></i><span class="badge border border-secondary mr-2"><h2 class="h6 mb-0 small"><a class="text-secondary" href="tag-2.html">9cbs</a></h2></span></div></div></div></div><div class="card card-postlist border-white shadow"><div class="card-body"><div class="card-title"><div class="d-flex justify-content-between"><div><b>New Post</b>(<span class="posts">0</span>) </div><div></div></div></div><ul class="postlist list-unstyled"> </ul></div></div><div class="d-none threadlist"><input type="checkbox" name="modtid" value="4123" checked /></div></div></div></div></div><footer class="text-muted small bg-dark py-4 mt-3" id="footer"><div class="container"><div class="row"><div class="col">CopyRight © 2020 All Rights Reserved </div><div class="col text-right">Processed: <b>0.047</b>, SQL: <b>9</b></div></div></div></footer><script src="./lang/en-us/lang.js?2.2.0"></script><script src="view/js/jquery.min.js?2.2.0"></script><script src="view/js/popper.min.js?2.2.0"></script><script src="view/js/bootstrap.min.js?2.2.0"></script><script src="view/js/xiuno.js?2.2.0"></script><script src="view/js/bootstrap-plugin.js?2.2.0"></script><script src="view/js/async.min.js?2.2.0"></script><script src="view/js/form.js?2.2.0"></script><script> var debug = DEBUG = 0; var url_rewrite_on = 1; var url_path = './'; var forumarr = {"1":"Tech"}; var fid = 1; var uid = 0; var gid = 0; xn.options.water_image_url = 'view/img/water-small.png'; </script><script src="view/js/wellcms.js?2.2.0"></script><a class="scroll-to-top rounded" href="javascript:void(0);"><i class="icon-angle-up"></i></a><a class="scroll-to-bottom rounded" href="javascript:void(0);" style="display: inline;"><i class="icon-angle-down"></i></a></body></html><script> var forum_url = 'list-1.html'; var safe_token = 'jow9jj4HcHXvElXSG94iXg9mHEGlCzwVTPKWj7u5BUdeSiEL8hTbKAQyEJrHwGAs5_2BOaN4OFm9XzwTbaTHhoUA_3D_3D'; var body = $('body'); body.on('submit', '#form', function() { var jthis = $(this); var jsubmit = jthis.find('#submit'); jthis.reset(); jsubmit.button('loading'); var postdata = jthis.serializeObject(); $.xpost(jthis.attr('action'), postdata, function(code, message) { if(code == 0) { location.reload(); } else { $.alert(message); jsubmit.button('reset'); } }); return false; }); function resize_image() { var jmessagelist = $('div.message'); var first_width = jmessagelist.width(); jmessagelist.each(function() { var jdiv = $(this); var maxwidth = jdiv.attr('isfirst') ? first_width : jdiv.width(); var jmessage_width = Math.min(jdiv.width(), maxwidth); jdiv.find('img, embed, iframe, video').each(function() { var jimg = $(this); var img_width = this.org_width; var img_height = this.org_height; if(!img_width) { var img_width = jimg.attr('width'); var img_height = jimg.attr('height'); this.org_width = img_width; this.org_height = img_height; } if(img_width > jmessage_width) { if(this.tagName == 'IMG') { jimg.width(jmessage_width); jimg.css('height', 'auto'); jimg.css('cursor', 'pointer'); jimg.on('click', function() { }); } else { jimg.width(jmessage_width); var height = (img_height / img_width) * jimg.width(); jimg.height(height); } } }); }); } function resize_table() { $('div.message').each(function() { var jdiv = $(this); jdiv.find('table').addClass('table').wrap('<div class="table-responsive"></div>'); }); } $(function() { resize_image(); resize_table(); $(window).on('resize', resize_image); }); var jmessage = $('#message'); jmessage.on('focus', function() {if(jmessage.t) { clearTimeout(jmessage.t); jmessage.t = null; } jmessage.css('height', '6rem'); }); jmessage.on('blur', function() {jmessage.t = setTimeout(function() { jmessage.css('height', '2.5rem');}, 1000); }); $('#nav li[data-active="fid-1"]').addClass('active'); </script>