Cookies summarized!

Are you preparing for IT certification? With practice questions, study notes, interactive quizzes, tips and technical articles, uCertify PrepKits ensure that you get a solid grasp of core technical concepts to ace your certification exam in first attempt.

Cookies summarized!

Rating:

A cookie is a block of data stored on a client computer by a Web server. If no expiration date is set for a cookie, the cookie expires when the browser is closed. If the expiration date is set for a future date, the cookie is stored on the client's disk after the session ends, and if set for a past date, the cookie is deleted.

The following attributes are used with a cookie:

  • name=value: This is the only attribute that is required to generate a cookie.

  • expires=date: This is an optional attribute and is used to set the expiry date of a cookie.

  • path=path: This is an optional attribute and is used to set the path of a cookie.

  • domain=domain: This is an optional attribute and is used to set the domain for a cookie.

  • secure: This attribute is also optional. If this attribute is set, the cookie is read only by secure sites.
How to create a cookie through JavaScript

The cookie is a property of the document object. It is used for sending and receiving data between the Web browser and a Web server.

Cookies can be created in JavaScript by using the following syntax:

document.cookie="cookiename=cookiedata
      [; expires=timeinGMTstring]
      [; path=pathname]
      [; domain=domainname]
      [; secure]"


where,
  • The cookiename is the name with which the cookie will be saved on the client computer.

  • The cookiedata is the data that is sent through the cookie.

  • The expires attribute is set to delete the cookie file after a certain date. The date should be converted to GMT string.

  • The path attribute is used to set the path of the directory from which the cookie is active.

  • The domain is used to search the domain to which the cookie is to be sent.

  • If the secure attribute is set, the cookies can only be accessible on the sites with secure connections.
How to delete a cookie

If the expires attribute is specified, the cookie is automatically deleted after the expiration date. To delete a cookie before the expiration date, the date and time of the cookie has to be changed to an earlier date in the cookie file. If the expires attribute is not specified, the cookie is deleted after the session is completed.

Some important facts about cookies are as follows:
  • Cookies can be used to target users for marketing purposes.

  • Cookies are sent from a server to the user's browser through an HTTP response header.

  • Cookies can be used to store passwords.

  • Cookies cannot be stored at multiple locations on users' computers.

  • Cookies cannot contain viruses.


Rating:



Other articles

Click here to Article home

 
uCertify.com | Our Company | Articles | Privacy | Security | Contact Us | News and Press Release | uCertify India
MCSE: MCSA, MCTS, MCITP    JAVA Certification: SCJP, SCWCD Cisco Certification: CCNA, CCENT, A+, Network+, Security+
Oracle Certification: OCP 9i, OCP 10g, OCA 9i, OCA 10g CIW foundation    EC-212-32    CISSP    Photoshop ACE    Adobe Flash ACE
© 2008 uCertify.com. All rights reserved. All trademarks are the property of their respective owners.