Home >Backend Development >PHP Tutorial >ASP Knowledge Lecture 4_PHP Tutorial
ASP built-in components
In the first three lectures, we mainly introduced the four built-in objects provided by ASP:
l Response object: Send information to the browser.
l Request object: access information sent from the browser to the server (such as obtaining form data).
l Session object: stores and reads specific user conversation information.
l Application object: stores and reads application information shared by all users.
In addition, there are Server objects and ObjectContext objects that we will learn in future examples (hint: in fact, you can already use the knowledge you have learned to write an online chat room without realizing it). The content of this lecture is the use of ASP's ActiveX Server Components (components).
1. Browser Capabilities Component:
We know that different browsers may support different functions. For example, some browsers support frames and some do not. Using this component, you can check the browser's ability to make your web page display different pages for different browsers (such as displaying web pages without Frame for browsers that do not support Frame). The use of this component is very simple. It should be noted that to use this component correctly, you must ensure that the Browscap.ini file is up to date (in fact, every browser and its features are listed in this file. You will understand after opening it yourself. ), otherwise the results may be very different. For example, IE5.0 included in the second version of Win98 is displayed as Netscape in the following example. This file is generally located under "WinntSystem32InetSrv" on the Web server. The latest version can be downloaded from http://www.asptracker.com/ or http://www.cyscape.com/browscap.
Example: wuf22.asp
Browser Type | <%=BrowsCap.Browser%> |
Browser Version | <%=BrowsCap.version%> |
<%=BrowsCap.tables%> | |
Whether it supports ActiveX controls< /TD> | <%=BrowsCap.activexcontrols%> |
Whether JavaApplets are supported | < ;%=BrowsCap.javaapplets%> |
Whether JavaScript is supported | <%=BrowsCap.javascript%> ; |
Whether Cookies are supported | <%=BrowsCap.Cookies%> | < /TR>
Whether Frames are supported | <%=BrowsCap.Frames%> | Operating system | <%=BrowsCap.Platform%> |
Whether it is supported VBScript | <%=BrowsCap.vbscript%> |
First string; " 'Write string
CTF.WriteLine "Second string; " 'Write string, and add A newline character
CTF.Write "The third string; "
CTF.Close 'Be careful to close the file
' Read file operation
Set CTF = FSO.OpenTextFile(File, 1,,0)
Do While CTF.AtEndOfStream <> True 'Determine whether the file ends (loop statement)
Str = CTF.ReadLine '(Every time) Read one line
StrNoHTML = StrNoHTML & Str & "
" & VbCrLf
StrHTML = StrHTML & Server.HTMLEncode(Str) & "
" & VbCrLf
Loop
Response.Write StrNoHTML
Response.Write StrHTML
CTF.Close
Set CTF = Nothing 'Release object
Set FSO = Nothing
%>
CTF = FSO.OpenTextFile(File, 8, False, 0), The first parameter in brackets is the file name; the second parameter is 8, which means appending content after the original file. If it is 1, it means read-only, and if it is 2, the original file will be overwritten; the third parameter, false, means that if the file is specified If it does not exist, the file will not be created. If it is True, it means that the specified file does not exist, and the file will be created; the fourth parameter 0 means opening it in ASCII file format, and if it is -2, it means opening it in the original format.
CTF = FSO.CreateTextFile(File,False, False), the second parameter false means not to overwrite the existing file, if it is True, it means overwrite the existing file; the third parameter False means the file The format is ASCII. True means the file format is Unicode.
The MapPath method of the Server object converts the specified virtual path into a real file path. MapPath treats "/" and "" characters as the same.
The HTMLEncode method of the Server object allows you to HTML encode a specific string, or enable the browser to display specific characters correctly. In the above example, if it is not encoded, "
" will not be displayed, but will be marked as HTML by the browser. You can compare the running results.
In fact, the File Access component is relatively powerful in operating files, folders and drives, and it also provides more methods. If you need to use this knowledge, don’t forget to use it.
In addition, by now, writing a webpage counter is a piece of cake. No wonder so many webpages provide free counters. How about it? Try writing a graphical counter yourself. You can cheat as much as you want. You have the final say. It’s so cool! (A little secret: I have an instance wuf24.asp on my homepage)
3. AD Rotator (advertising flipping component)
When surfing the Internet now, I am afraid that the most annoying thing is the advertising banners on other people’s homepages. My favorite It's an advertising banner on your homepage. Advertising banners are everywhere like spam, making them hard to guard against. You can also create such garbage yourself. ASP's AD Rotator component can randomly display ads every time you open or reload a web page.This example includes three parts:
Routine wuf25.asp
<%@ Language=VBScript %>
<% Option Explicit
Dim adr
'Create AD Rotator object
Set adr = Server.CreateObject("MSWC.AdRotator")
adr.Border = 2 'Specify the border size of the graphic file
adr.Clickable = True 'Indicate whether the displayed image is a hyperlink
adr.TargetFrame = "_blank" 'Whether to specify the Frame name when setting the hyperlink, such as: _TOP _NEW _PARENT
'Get the image and hyperlink settings to be displayed - set
Response.Write adr in the file AdrSet.txt .GetAdvertisement("AdrSet.txt")
%>
AdrSet.txt content (followed by comments, not the content of this file):
REDIRECT wuf26.asp After clicking on the advertisement, transfer to wuf26.asp To handle
WIDTH 468 Advertising Image Width
HEIGHT 60 Advertising Image Height
* Separator
http://www.soyou.com/prog/ad/468x60_1.gif The location of the advertising image, also It can be a local graphic file
http://www.163.com/ pointing to a link. If there is no hyperlink, write a "-"
NetEase text description
20 to display the relative weight of the advertisement, that is Display frequency
http://fp.cache.imgis.com/images/Ad173962St1Sz1Sq1Id2.gif
http://www.sina.com.cn/
Sina
30
http ://61.139.77.73/images/canon.gif You can also use local images, such as ../images/flag.gif
http://www.canon.com.cn/
Canon
50
In this example, there are three pictures (picture size 468X60) and links. The description of each link takes up four lines. In actual use, you can follow the same method and add more pictures.
<% 'wuf26.asp
URL = Request.QueryString("url")
Response.Redirect(URL)
%>
wuf26.asp is the simplest processing program, you can add more code here according to actual needs.
Run it. It turns out that the use of this component is also very simple. All you have to do is get your own AdrSet.txt file. Using this component, you can even design an ad exchange homepage that is now very trendy.
4. Content Linking component
Obviously this component is related to links. If you want to know the specific use of this component right away, I am afraid it is too hasty. You might as well quote a classic example first: Suppose you are reading a book on the Internet Books, you must be familiar with the following links: Chapter 1, Chapter 2,..., previous chapter, next chapter (or previous page, next page), etc. What we have to do now is how to set up jumps between these links easily and quickly.
First create a link list text file, such as urllist.txt
wuf23.asp Chapter 1: File Operation (File Access component)
wuf28.asp Chapter 2: Content Linking component usage example
wuf22.asp Chapter 3: Browser Capability Component
The link URL address and description are separated by the Tab key. The following wuf27.asp is used to list all links in urllist.txt.
<% @LANGUAGE = VBScript %>
<% Option Explicit %>
Here is the text of Chapter 2......