Exp 10
Exp 10
10
Aim: Develop a Web page for creating session cookies and persistent cookies. Observe the effects with
browser cookie settings.
Theory:
Cookies are data stored in small text file that a web site server writes on client’s hard disk. Cookies are created by the
web server when a requested web page is loaded on client’s web browser. Cookie can be used to store information
(plain text) in a text file based on the application’s requirement.
Types of cookie:
1. Session cookie: It resides in client’s memory till the session is active. A browser session begins when user
request for a website on browser and ends when user closes the web site. When user is working with a web
site his session is active and for this period a cookie created by server will remain in user’s PC.
2. Persistent cookie: It is a cookie with assigned expiry date. When user request for a web site on a browser, a
cookie is created by server and stored on client’s machine. This cookie is created with expiry date so the
cookie resides on client’s machine till its expiry date. The cookie may reside on client’s machine for few
hours, days, months and years.
Expires − The date the cookie will expire. If this is blank, the cookie will expire when the visitor
quits the browser.
Domain − The domain name of your site.
Path − The path to the directory or web page that set the cookie. This may be blank if you want to
retrieve the cookie from any directory or page.
Secure − If this field contains the word "secure", then the cookie may only be retrieved with a secure
server. If this field is blank, no such restriction exists.
Name=Value − Cookies are set and retrieved in the form of key-value pairs. The text stored inside a
cookie file contains information in the form name-value pair which stores name of the field and its
value. For example, if username is the field name then xyz can be a value stored inside it. Semicolon,
comma, white space is not allowed in the name of cookie. To use these characters, escape character
(\) is used before them. The escape character tells the browser that the semicolon, comma or white
space is part of the name or value and not a special character.
Each cookie has four parts: name, assignment operator, value and semicolon. Semicolon is a delimiter. It is a
character that indicates end of cookie.
cookiearray = allcookies.split(';');
for(var i=0; i<cookiearray.length; i++)
{
name = cookiearray[i].split('=')[0];
value = cookiearray[i].split('=')[1];
document.write ("<br>Key is : " + name + " and Value is : " + value);
}
}
</script>
</head>
<body>
<form name = "myform" action = "">
Enter name: <input type = "text" name = "customer"/>
<input type = "button" value = "Set Cookie" onclick = "WriteCookie()"/>
<input type="button" value="Read Cookie" onclick="ReadCookie()"/>
</form>
</body>
</html>
Conclusion:
With all the concepts based on cookies creation,deletion and manipulation , successfully executed all
programs with correct output.