Like somuch.com on Facebook Share somuch.com on Facebook somuch.com on Twitter Reddit LinkedIn Pinterest
Newest Tips & Tricks...

Home :: Tips & Tricks :: Active Server Pages

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("<FORM Method=Post>Enter Your Name: ")
Response.Write("<INPUT Type=Text Name=Name> ")
Response.Write("<INPUT Type=Submit></FORM>")
ELSE
Response.Write("Welcome back, "&Request.Cookies("Name"))
END IF
%>

Source: Anonymous

Recommended Links...