521Chapter 18The Document and Body ObjectsA cookie file (Web site hosting)
Friday, August 31st, 2007521Chapter 18The Document and Body ObjectsA cookie file is a text file. If curiosity drives you to open a cookie file, I recommend you do soonly with a copy saved in another directory or folder. Any alteration to the existing file canmess up whatever valuable cookies are stored there for sites you regularly visit. The data for- mat for cookie files differs across browsers, in line with the different methodologies used forfiling cookies. Inside the Netscape/Mozilla file (after a few comment lines warning you not tomanually alter the file) are lines of tab-delimited text. Each return-delimited line contains onecookie s information. The cookie file is just like a text listing of a database. In each of the IEcookie files, the same data points are stored for a cookie as for Navigator, but the items are ina return-delimited list. The structure of these files is of no importance to scripting cookies, because all browsers utilize the same syntax for reading and writing cookies through thedocument.cookieproperty. As you experiment with browser s cookies, you will be tempted to look into the cookie fileafter a script writes some data to the cookie. The cookie file usually will not contain thenewly written data, because in most browsers cookies are transferred to disk only when theuser quits the browser; conversely, the cookie file is read into the browser s memory when itis launched. While you read, write, and delete cookies during a browser session, all activity isperformed in memory (to speed up the process) to be saved later. A cookie recordAmong the fields of each cookie record are the following (not necessarily in this order): .Domain of the server that created the cookie .Information on whether you need a secure HTTP connection to access the cookie .Pathname of URL(s) capable of accessing the cookie .Expiration date of the cookie .Name of the cookie entry .String data associated with the cookie entryNotice that cookies are domain-specific. In other words, if one domain creates a cookie, another domain cannot access it through the browser s cookie mechanism behind your back. That reason is why it s generally safe to store what I call throwaway passwords(the user- name/password pairs required to access some free registration-required sites) in cookies. Moreover, sites that store passwords in a cookie usually do so as encrypted strings, making itmore difficult for someone to hijack the cookie file from your unattended PC and figure outwhat your personal password scheme may be. Cookies also have expiration dates. Because some browsers may allow no more than a fixednumber of cookies (300 in NN), the cookie file can get pretty full over the years. Therefore, if acookie needs to persist past the current browser session, it should have an expiration dateestablished by the cookie writer. Browsers automatically clean out any expired cookies. Not all cookies have to last beyond the current session, however. In fact, a scenario in whichyou use cookies temporarily while working your way through a Web site is quite typical. Many shopping sites employ one or more temporary cookie records to behave as the shop- ping cart for recording items you intend to purchase. These items are copied to the orderform at checkout time. But after you submit the order form to the server, that client-side datahas no particular value. As it turns out, if your script does not specify an expiration date, thebrowser keeps the cookie fresh in memory without writing it to the cookie file. When you quitthe browser, that cookie data disappears as expected. Notedocument.cookie
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.