Use "cookies" in ASP

Source: Internet
Author: User
All the friends who have been on the net know that cookies, known as the "cookie" of this network technology. Cookies are a small Che Wen that the server sends to the client.
This handle, the Web site by sending cookies to the viewer method to store some specific information on the user's local hard drive, waiting for users to visit the site again can
Read the stored information from the hard drive to complete some actions, such as a website that allows visitors to customize the page to "remember" the user with the Cookies technology
Custom hobby, and some e-commerce sites are also widely used cookies.

Many people worry that the use of cookies can bring security problems, but this worry is not necessary, because cookies information can not be obtained across the site, but in order to eliminate
People's "Doubt", many browsers have provided the option to block cookies.

Perhaps you think that cookies technology is difficult to achieve, in fact, please see the following example, this example is mainly through cookies to make the site "remember" visitors
Some personal information, such as name, age, etc., so that when a visitor logs on to the site again, the site can display some of the visitors
Welcome information, such as "So-and-So, hello", is not very kind?

Code listings:

Enrol.asp

<%

Response.Cookies ("Information") ("name") =request.form ("name")

Response.Cookies ("Information") ("Age") =request.form ("Age")

Response.Cookies ("Information") ("Nation") =request.form ("Nation")

%>



<title>cookies demo</title>


<body>

<form method= "POST" action= "enrol.asp" >

Name:

<input type= "text" name= "name" >

<p>

Age:

<input type= "text" name= "age" >

<p>

Nation:<input type= "text" name= "Nation" >

<p>

<input type= "Submit" >

<input type= "Reset" >

</form>

</body>


The code is an ASP program, but is essentially a text file, so you can use the "notepad" edit, the other local debugging needs PWS4.0, the above code to save into
ASP file, named Enrol.asp, save path C:\Inetpub\wwwroot (PWS default installation).

The program defines a cookie dictionary, named information, with three subkeys: Name, age, and nation, which are used to record the visitor's last name, respectively.
Name, age and country, if you still need more information on your visitors, you can define more subkeys.

Run PWS, open the browser, enter http://localhost/enrol.asp in the Address bar, and a form appears asking visitors to fill out their personal information when
After the visitor has completed submitting the form, his personal data is stored on the user's hard drive by cookies, which is available for the next time the website reads, the following
ASP file demonstrates how to read information from cookies in the process, the ASP file save path with enrol.asp, file name is feedback.asp, run
When you type http://localhost/feedback.asp in the browser's address bar, the contents of the cookies are displayed on the page.

Feedback.asp



<title>cookies demo</title>


<body>

Name:

<%=request.cookies ("Information") ("name")%>

<p>

Age

<%=request.cookies ("Information") ("Age")%>

<p>

Nation

<%=request.cookies ("Information") ("Nation")%>

</body>



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