The web servers
cannot store the information or the history of the user. Once the browser
request has been fulfilled the information about the browser’s previous
actions will be lost. For example, the information such as which page
was clicked, or which image was clicked will be lost. The web server cannot
maintain the state of the user session. However, the maintaining the state
of the user is desirable most of the times and therefore cookies are used.
a variable that stores the information about the user session. It can
store the name, date, or the pages being visited by the user. The cookies
are stored on the user’s computer and when the user requests the same
page from the same browser, the cookie is sent to the server and help
server to identify the user and displays the name or the other information
of the user on the web page requested. There are different types of cookies
such as name cookies - that store the name of the user and helps in displaying
a welcome message for the user, password cookies - that stores the passwords
of the user and saves user from typing the password every time the user
visits the same website, date cookies – that stores the date and time
of the visit on the web page of the user and helps in displaying the last
visit date and time of the user.
are however, expired after certain time. After which they will no longer
read a cookie. To create a cookie, you need to use the code:
= ”name=<cookiename>;expires=< expirydate>;path=<path>;domain=<domain>;secure”;
of each property is as follows:
Name= Name of the cookie.
Expires= Expiry date of the cookie in format weekday ddmmyy hh:mm:ss GMT.
By default the expiry date is set to the end of the current session.
Path= The directory path where the cookie is active or the portion of
the URL for which cookie is valid. Usually the path is set to “/”which
means the cookie is valid during the entire program.
Domain name= Domain portion of the URL for which the cookie is valid.
Secure = Specifies that the cookie should be transmitted over a secure
To set a
cookie you can write the code, as shown below:
if cookie is already set
if the cookie value is not equal to the data entered by the user
(index == -1)
expires=Saturday, 04-Dec-2010 05:00:00
is set with value: "+ValueEntered);
the value for cookie: <INPUT TYPE="text" NAME="text1" size="20">
TYPE="button" Value="Set to Cookie"
result of the code
To get the
value of cookie, you need to write the function as:
(ind==-1 || cookieName=="") return "";
the cookie, you need to write the function as:
deletecookie ( cookiename )
var cookiedate = new Date ( ); // current date & time
cookiedate.setTime ( cookiedate.getTime() - 1 );
document.cookie = cookiename += "=; expires=" + cookiedate.toGMTString();