Java Reference
In-Depth Information
Generally, by default session cookies — cookies that last for only as long as the user is browsing your
web site — are allowed. As soon as the user closes the browser, the session ends. However, if you want
cookies to outlast the user's visit to your web site, you need to create a privacy policy in line with the
P3P recommendations. This sounds a little complex, and certainly the fi ne details of the policy can be.
However, IBM has created software that makes creating the XML for the policy fairly easy. It's not
cheap, but there is a 90-day free trial. It can be downloaded from www.alphaworks.ibm.com/tech/
p3peditor.
Plenty of other policy creation software is available; this just happens to be quite easy to use. P3PEdit is
available for much lower cost from http://policyeditor.com/.
Summary
In this chapter, you looked at how you can store information on the user's computer and use this infor-
mation to personalize the web site. In particular you found the following:
The key to cookies is the
document object's cookie property.
Creating a cookie simply involves setting the
document.cookie property. Cookies have six
different parts you can set. These are the name, the value, when it expires, the path it is avail-
able on, the domain it's available on, and fi nally whether it should be sent only over secure
connections.
Although setting a new cookie is fairly easy, you found that retrieving its value actually gets all
the cookies for that domain and path, and that you need to split up the cookie name/value pairs
to get a specifi c cookie using String object methods.
Cookies have a number of limitations. First, the user can set the browser to disable cookies, and
second, you are limited to 50 cookies per domain in IE7+ and Firefox and a maximum of 4,096
characters per cookie name/value pair.
Exercise Questions
Suggested solutions to these questions can be found in Appendix A.
1.
Create a page that keeps track of how many times the page has been visited by the user in the
last month.
2.
Use cookies to load a different advertisement every time a user visits a web page.
Search WWH ::




Custom Search