Cookies, those small files that live in the Temporary Internet Files
folder, are a great way to personalize your ASP pages.
The following ASP 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.
<%
If Not Request.Form("Name") = "" Then
Response.Cookies("Name") = Request.Form("Name")
Response.Cookies("Name").Expires = "Jan 1, 2010"
End If
%>
<html>
<head>
<title>Welcome Page</title>
</head>
<body>
<%
If Request.Cookies("Name") = "" Then
Response.Write "<form method=""post"">Enter Your Name: "
Response.Write "<input type=""text"" name=""name"">"
Response.Write "<input type=""submit"">"
Response.Write "</form>"
Else
Response.Write "Welcome back, " & Request.Cookies("Name")
End If
%>
</body>
</html>
If you have a tip you would like to submit, please send it to:
webmaster@asp101.com.