Using Cookies in your ASP page

Cookies, those small files that live in the Temporary Internet Files folder, are a great way to personalize your Active Server web pages. The following ASP/HTML code creates a page that will ask a user to enter their name the first time they visit the page, then recognize and greet them by name each subsequent visit.

At the top of your page:

<%
IF NOT (Request.Form("Name") = "") THEN
Response.Cookies("Name") = Request.Form("Name")
Response.Cookies("Name").Expires = "Jan 1, 2000"
END IF
%>

In the Body of your page:

<%
IF Request.Cookies("Name") = "" THEN
Response.Write("

Enter Your Name: ")
Response.Write(" ")
Response.Write("
")
ELSE
Response.Write("Welcome back, "&Request.Cookies("Name"))
END IF
%>

Source: Anonymous
Viewed 15761 times