Recommended: Common 80004005 errors and their solutions In the process of writing WEB applications, we often have to deal with databases, such as the database ACCESS, SQL SERVER, which we often use in daily life. When connecting these databases, the system often gives us some errors like 80004005.
What are cookies? Cookie is actually a tag, which is often heard in Chinese: Little Licking Cookie. When you visit a WEB site that needs to uniquely identify your site, it will leave a tag on your hard drive, and the next time you visit the same site, the site's page will look for this tag.
Each WEB site has its own tag, and the tagged content can be read at any time, but it can only be done by the pages of that site. Cookies for each site exist in different files in the same folder as cookies for all other sites (you can find them in the Cookies folder in the Windows directory of win98, while win2k is in the Cookies folder for specific users under the Documents and Settings folder).
A cookie is a tag that uniquely identifies a customer. A cookie can contain information shared by all pages of a WEB site between a conversation period or several conversation periods. Using cookies can also exchange information between pages. This feature is often used in ASP programs such as requiring authenticated customer passwords and electronic bulletin boards, WEB chat rooms, etc.
Although cookies sound nothing exciting now, in fact, you can achieve many meaningful features with it! For example: you can place a question and answer sheet on the site, ask the visitor for favorite colors and fonts, and then customize the user's web interface based on these. In addition, you can also save the visitor's login password, so that when the visitor visits the site again, you no longer need to enter the password to log in.
Of course, cookies also have some shortcomings. First of all, since the function of cookies can be used to program and implement some bad attempts, most browsers have security settings, which can set whether to allow or accept cookies (the tool-Internet option in IE browser...--Security-Customization level--Cookies use; the tool--Cookie Manager---manage stored cookies in Netscape browser), so this cannot guarantee that cookies can be used at any time. Furthermore, visitors may intentionally or unintentionally delete cookies. When the visitor's machine encounters a blue screen of death, or after reformatting the hard disk or installing the system, all the original saved cookies will be lost. Last but not least, some initial browsers do not support cookies.
◆ How to use cooklie?
There are 2 basic ways to use cookies:
1. Write cookies to the visitor's computer (using the Response command)
2. Retrieve the cookie from the visitor's computer (using the Request command)
◆ Basic syntax for creating cookies: Response.Cookies(cookie)[(key)|.attribute]=value
The cookie here is the name of the specified cookie.
And if a key is specified, the cookie is a dictionary.
(Test whether a cookie is a dictionary or not, which can be used to display the boolean value in the following code: <%=Request.Cookies(cookiename).HasKeys%>. If true is a dictionary, false is not.)
Attribute Specifies the information about the cookie itself. The Attribute parameter can be one of the following:
①If Domain is specified, the cookie will be sent to the request for the domain. The domain attribute indicates which website the cookie is generated or read. By default, the domain attribute of the cookie is set to the website that generates it, but you can also change it as needed. (Response.Cookies(CookieName).Domain = www.CuoXIn.com)
②Path is a path attribute, which can achieve more security requirements. By setting the precise path on the website, you can limit the scope of use of cookies. If this property is not set, the path to the application is used. (Response.Cookies(CookieName).Path = /maindir/subdir/path)
③Expires Specifies the expiration date of the cookie. In order to store cookies on client disk after the session ends, or in many cases, we want to save cookies on the visitor's computer for longer. This date must be set. If the setting of this property does not exceed the current date, the cookie will expire after the task is over.
The following code can set the expiration date of cookies to January 1, 2010: Response.Cookies(CookieName).Expires=#January 01, 2010#
The following code will set the expiration time of the cookie to the creation time of the cookie + 365 days: Response.Cookies(CookieName).Expires=Date 365
But it is best not to write Response.Cookies(CookieName).Expires=Date casually, so that the value will be empty when calling between pages.
Execute the following code to create a cookie in the visitor's computer, name = VisitorName, value = Ken:
Response.Cookies(VisitorName)=Ken
Execute the following code to create a cookie in the visitor's computer, name = VisitorName, value = UserName value in the form
Response.Cookies(VisitorName)=Request.Form(UserName)
You can extend the following code to become the Cookie subkey value (CookieSubName), that is, the generation of the cookie dictionary. The code is as follows:
Response.Cookies(VisitorName)(FirstName)=Ken
Response.Cookies(VisitorName)(LastName)=Baumbach
◆ Basic syntax for reading cookies: Request.Cookies(cookie)[(key)|.attribute]
cookie Specifies the cookie whose value you want to retrieve.
key optional parameter to retrieve the value of a subkeyword from the cookie dictionary.
attribe Specifies the cookie's own information. For example: HasKeys is read-only, specifying whether the cookie contains keywords.
If the client browser sends two cookies with the same name, the Request.Cookie returns the one with the deeper path structure. For example, if there are two cookies with the same name, but one of them has a path attribute of /www/ and the other is /www/home/, and the client browser sends both cookies to the /www/home/ directory at the same time, the Request.Cookie will only return the second cookie.
Case analysis:
◆ num.asp (record the number of visits to this site within one year through cookies left on the local disk, displaying the first visit for the first time, and displaying the first visit in the future)
| The following is the quoted content: <% dim num num=request.cookies(visitnum) if num > 0 then num=num 1 Response.write You have visited this site for the first time. else Response.write Welcome to visit this site for the first time. num=1 end if response.cookies(visitnum)=num response.cookies(visitnum).expires=date 365 %> |
◆ showcookie.asp (traverses all the browser's cookie names and displays related dictionary cookies (blue characters) from the Cookies folder)
| The following is the quoted content: <% For each cookie in Request.Cookies if Request.cookies(cookie).HasKeys =false then Response.write cookie & = & Request.Cookies(cookie) Response.write (<br>) Else for each key in Request.Cookies(cookies) Response.write (<font color=blue>) Response.write cookie & .(&key&) & = & Request.Cookies(cookie)(key) Response.write (</font><br>) next end if next %> |
◆ check.asp
'First, set the page. Then, check the form variable (in the same page). If the form variable exists, create a cookie and set the expiration time.
| The following is the quoted content: <%@ LANGUAGE=VBSCRIPT %> <% bgcolor = Request.Form(bgcolor) fgcolor = Request.Form(fgcolor) pwd = Request.form(pwd) If bgcolor <> or fgcolor <> then Response.cookies(check)(bgcolor) = bgcolor Response.Cookies(check)(fgcolor) = fgcolor Response.Cookies(check)(pwd) = pwd Response.Cookies(check).Expires=#may 01, 2004# End if 'Next, read the cookie bgcolor = request.cookies(check)(bgcolor) fgcolor = request.cookies(check)(fgcolor) pwd = request.cookies(check)(pwd) 'If the cookie does not exist on the visitor's computer, create a form and ask for relevant information If bgcolor = and fgcolor = and pwd= then %> <HTML> <HEAD> </HEAD> <body> <DIV ALIGN=CENTER > <Form action=check.asp method=POST> Bgcolor: <input type=text name=bgcolor><BR> Fgcolor: <input type=text name=fgcolor><BR> Password:<input type=password name=pwd><BR> <input type=submit value=Submit> </Form> </DIV> </BODY> <% End if 'If the cookie already exists and bgcolor exists, jump to color.asp. If bgcolor <> then Response.Redirect color.asp End if %> |
◆ color.asp (the page characteristics that display the user's favorite colors)
| The following is the quoted content: <% bgcolor=request.cookies(check)(bgcolor) fgcolor=request.cookies(check)(fgcolor) pwd=request.cookies(check)(pwd) %> <%response.write(<body bgcolor=&bgcolor&><font color=&fgcolor&>)%> Your password is: <%response.write( &pwd& )%> |