ASP Getting Started Tutorial-cookies collection

Source: Internet
Author: User
Tags reset

Create cookies by collecting cookies from a response object. The syntax format is:

Response.Cookies (Cookies名) [(key)|.属性] =值

Note: Key is an optional parameter, such as the specified key, then the cookie is a dictionary, the parameter value will be set to "value". And can be used in future reception. Index value is used to retrieve one of several variable values, and properties refer to the properties of the cookies. The cookie default lifecycle starts at the moment it is written to the browser end, and ends at the end of the browser's execution. If you want to set the lifetime of the cookise, you can use Response.Cookies (name). Expries property. Cookies are automatically removed from the browser's native disk when the expiration date is full.

Cookies can be read out through the collection of cookies from the request object and delivered to the server side. The syntax format is:

Request.Cookies (Cookies名)

Among them, the cookie name is the name of the cookie that has been created.

Third, cookies properties

property name description
expires cookies Expiration Date, in order to store cookies on the client disk after the session has ended, you must set the date. If the setting of this property does not exceed the current date, the cookie expires at the end of the task and writes only the property.
secure to set cookies Whether it is delivered in a secure channel. When a secure channel is not found on the HTTP home page, the cookie information will not be sent.
haskeys designation cookies are Contains key keys, read-only properties.

Using cookies to make a simple web counter, the form submits the page with the following code: (FileName: 4-3g.htm)

<form name="Form1" method="get" action="4-3g.asp">
<p>姓名:<input name="txtuserName" type="text">
<p>性别:<input name="optUserSex" type="radio" value="男">男&nbsp;&nbsp;
<input name="optUserSex" type="radio" value="女">女
<input Type="submit" name="btnSubmit" value="提交">&nbsp;&nbsp;
<input type="reset" name="reset" value="重写">

The code for the Process page (filename: 4-3g.asp) that counts how many times this page is accessed is as follows:

<% @ language= "VBScript"%>
<% response.buffer=true%>
<title> Read and write cookies example </title>
N=request.cookies ("User") ("Visitedtimes")
Txtusername=request.querystring ("txtUserName")
Optusersex=request.querystring ("Optusersex")
If n= "" Then
End If
<font size= ' 7 ' color= ' Red ' face= ' Chinese cloud ' >
If optusersex= "male" then
Response.Write txtUserName & "Sir, you are welcome to visit this site!" "
ElseIf optusersex= "female" then
Response.Write txtUserName & "Miss, you are welcome to visit this site!" "
End If
Response.Write "<P> This page is currently accessed <b>" & N & "</b> times. </p> "
Response.Cookies ("User") ("Visitedtimes") =n
Response.Cookies ("User"). Expires=date () +7 ' setting a cookie named user is valid for 7 days.
<a href= "4-3g.htm" > Return to previous page </a>***| | <a href= "4-3-4.asp" > Return textbook </a>


Usually cookies are stored in the C:windowscookies directory (for the win98/me system), and for the WIN2000/XP system, cookies are usually stored in c:documents and The cookies subdirectory in the user directory in the settings. If the client closes the cookie option, the session will not work. In the IE6.0, click the Inetnet Options menu item on the Tools menu, open the Intenet Options dialog box, select the Privacy tab, click the Advanced button in the Advanced Privacy Policy Settings dialog box, and select the Overwrite automatic cookies check box And then select the "Reject" option, and then the cookies are turned off.

See the full set of ASP Getting started tutorials

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: 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.