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.
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.
cookie_name | the value | Expiration Date |
an attribute sent by the server | name choosen by user | Specified 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.
Let's Use JavaScript to fetch your Cookie Value.
<% @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="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> >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. --> </head> <body> <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" /> </p> <p> <input type="submit" value="Submit Information" name="submit" id="submit" /> <input type="reset" value="RESET" name="reset" id="reset" /> </p> </form>
·
·
<script type="text/javascript"> var thecookie; document.write("If you can read two lines before the red dashed line, both your JavaScript and cookies are turned on: <'br /> "); thecookie = document.cookie; document.write(thecookie + " which is decoded as: " + "<br />"); document.write(unescape(thecookie)); </script>
Return to Table of Contents