ASP Cookies Tutorial

Source: Internet
Author: User

ASP Cookies Tutorial is to record the user browsing information, but cookies can only save information to the client, but not also safe, many simple votes are used for cookies oh.

The same ASP session, ASP technology cookies are used to store information for specific visitors to your site. This cookie is stored on the user's computer for an extended amount of time. If you set the expiration date for the cookie in the future one day, it will continue their day before the arrival unless manually delete the user.

If you've read through session class you'll find that the code for ASP cookies has several similarities with ASP sessions.

Cookies created by ASP technology
Creating an ASP cookie is exactly the same process, creating an ASP session. Again, you must create a key/value pair where the key will be our name "created cookies." "The cookie that is created will store the value of the actual data."

In this example, we'll create a cookie called Brownie that stores how much brownie we eat during the day.

<%
' Create the cookie
Response.Cookies ("brownies") = 13
%>

Now that we have established this cookie, how do we get this information from the user's computer?

ASP technology to retrieve cookies
In order for our information to be stored in cookies, we have to request objects with ASP, providing a good way to store the cookies we retrieve on the user's computer. Below, we retrieve our cookies and print out their value.

<%
Dim Mybrownie
' Get the cookie
Mybrownie = Request.Cookies ("brownies")
Response.Write ("You Ate" & Mybrownie & "Brownies")
%>

Note: Be sure to see when you create a cookie using response.cookies, but when you retrieve a cookie you use Request.Cookies.

Cookie expiration date for ASP technology
With real life cookies, in ASP you can set how long you want your cookies to stay fresh and live on the user's computer. The expiration date of a cookie can be held, and the specified cookie will be destroyed on this date.

In our example below we create a cookie that will be good for 10 days for the first consideration of the current date and add another 10 to it.

' Create a 10-day cookie
Response.Cookies ("brownies") = 13
Response.Cookies ("Brownies"). Expires = Date () + 10
' Create a static date cookie
Response.Cookies ("name") = "Suzy Q."
Response.Cookies ("name"). Expires = #January 1,2009#

ASP Technology cookie array or collection
up to now, we can only store a variable to a cookie, which is quite limited if you want to store a lot of information. However, if we have this variable for collection it can be stored in large quantities. Below we make Brownie collection, storing all kinds of information.

' Create a big cookie
Response.Cookies (' Brownies ') (' numbereaten ') = #
Response.Cookies ("Brownies") ("ea ter ") =" George "
Response.Cookies (" Brownies ") (" weight ") = to

ASP Technology Retrieval COO Kie Value Collection
Now iterate through the collected brownie, we will use each loop. See our closed-loop tutorial for more information.

<%
for each key in Request.Cookies ("Brownies")
Response.Write ("<br/>" &A mp Key & "=" & _
Request.Cookies ("Brownies") (key)
Next
Response.Cookies ("Brownies") ("numbereaten") =
Response.Cookies ("Brownies") ("eater") = "George"
Response.Cookies ("Brownies") ("weight") =
%>

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.