First, this is the story of a user requesting something and someone reponding through a device called a server. It is a set of rules for requesting and responding.

Second, why do you want a Cookie? Are you Hungry for Knowledge??

A cookie is needed to maintain state. The protocol for the internet, Hypertext Transfer Protocol (HTTP), dosen't know who you are nor where you are going. The protocol does not know what page you recently used since HTTP only knows what page you just requested. During your Internet connection if you want or need any your pages linked together, you need the cookie to bound them. The cookie helps maintain the state of your session. Simply stated, the cookie identifies you- the computer user and/or client- to the host, the server, across multiple page requests. The cookie is just small bits of information that are exchanged between your browser and your Internet source. In summary, Cookies are a general mechanism which server side connections (such as CGI scripts) can use to both store and retrieve information on the client side of the connection. The addition of a simple, persistent, client-side state significantly extends the capabilities of Web-based client/server applications. The common misconception that it is something malicious just is not true. (It's not the cookie, but the site, stupid).
Wow! I worked for the federal government for years where this misconception was prevalent. Maybe, you can dispel this misconception and get our government on track.

Some ingredients: the small bits of information--

cookie_name the value Expiration Date
an attribute sent by the servername choosen by userSpecified by Web Programmer

A function setCookie() bakes the JavaScript Cookie--- setCookie(cookie_name, user_value, expiration_days)
Let's abbreviate the 3 ingredients as:cookie_n, user_v, and exp_days with the values mycookie, Jo4s98, 2.

Third, and last, now get your cookie. You can name it in the box then submit to the server:

Cookie Name:

Let's Use JavaScript to fetch your Cookie Value.

The following is the example of script that has been used to send a cookie from the server to the user. To send, as expressed, you need a server and server-side scripting.

<% @LANGUAGE = VBScript  %>
' Note that the ASP VBScript is running before the html is read
' Variables should be declared before they are called
' Retrieving Form Data from Post command body - the logic script

Dim strcookiename
If Request.ServerVariables("Content_Length") > 0 Then
	strcookiename = RequestForm("cookie_name")
	Response.Cookies("cookie_name") = strcookiename
	Response.Cookies("cookie_name").Expires = DateAdd("d",2,Now())
End If

<html xmlns="" xml:lang="en" lang="en"> 
	>meta http-equiv="Content-type" content="text/html;charset=iso-8859-1" />
<title>Simple Cookie</title>
<!-- #### This Exercise Hour 7 " Persisting Information about the User"
' ##This ASP page has a form taking the user's name as input.  Stores this name in a 
'permanent cookie 
'(expiration in two days),
' ## and whenever the page is opened again, default the name field to the cookie's content.
<form> action="<%= Request.ServerVariables("SCRIPT_NAME") %>" name="simplecookie" id="simplecookie" method="post" >
<p>Last Name:  
	<input type="text" name="cookie_name" id="cookie_name" size="20" value="Jo4s98" style="background-color: rgb(192,192,192); color:white"  />
	<input type="submit" value="Submit Information" name="submit" id="submit" />
	<input type="reset" value="RESET" name="reset" id="reset" />
<script type="text/javascript"> document.write("Can you read this"); document.write("<br />"); document.write(document.cookie); </script>

Return to Table of Contents