Open In App

Explain Persistent Cookie

Improve
Improve
Like Article
Like
Save
Share
Report

A Persistent Cookie is a small piece of data that is stored on a user’s computer and remains there after the user has closed their browser. They can be used to store user preferences and other information. Persistent cookies are used to improve the user experience by allowing website owners to store information that can be used to customize a user’s experience on a website. There are several characteristics of Persistent Cookie which are described below:

  • A Persistent Cookie is also known as a stored cookie, which is a small piece of data that is stored on a user’s computer by a web browser. It is stored on a user’s computer, as well, even after the web browser is closed. Even the Persistent Cookie can be used to store information that needs to be persistent across user sessions, such as a user’s preferences or login information. It is typically used in conjunction with a web server.
  • When a user visits a website, the web server sends the persistent cookie to the web browser & these cookies are small text files that a web server stores on a user’s computer. The file is saved in a location that is specific to the web browser. Each time the user loads the website, the browser sends the cookie back to the server to notify the website of the user’s previous activity.
  • They can also be used for marketing purposes, such as targeted advertising.
  • Some persistent cookies are set to expire after a certain amount of time, while others remain on the user’s computer indefinitely. So, the length of time can range from a few days to several years. They are typically stored on the user’s hard drive for a period of time that is determined by the website.
  • Most persistent cookies are “first-party” cookies, which means they are set by the website that the visitor is visiting. 
  • Some persistent cookies are “third-party” cookies, which means they are set by a website other than the one the visitor is visiting. 
  • However, persistent cookies can also be used for malicious purposes, such as tracking a user’s activity without their knowledge or consent.

Information provided by the persistent cookies may be shared with third-party organizations, such as advertisers and data brokers. Persistent cookies can make it difficult to keep users’ online activity private, as they can be used to track user’s across the web. So, it is difficult to protect users’ anonymity online. 

If users are concerned about user’s privacy and online security, users may have to consider disabling or deleting persistent cookies, user can usually do this through the browser settings. However, doing so may impact users’ experience on some websites, as persistent cookies are often used to store preferences and settings. Additionally, some persistent cookies are required for certain website features to work properly, such as online shopping carts. If a user is concerned about persistent cookies but still wants to use website features that require them, the user may want to consider using a private browsing mode or incognito window. This will prevent persistent cookies from being stored on the user’s device and can help to protect the user’s privacy and online security.

Components of Persistent Cookie: There are 4 components: 

  • Cookie name: It is a unique identifier for the cookie. 
  • Cookie value: It is the data that is stored in the cookie. 
  • Expiration date: It is the date when the cookie expires. 
  • Path: It is the path on the server where the cookie is stored.

Example 1: The following code example will add a persistent cookie with a name and value which will expire in 30 days.

PHP




<?PHP
    //setcookie() defines a cookie to be 
    //sent along with the other HTTP headers
      
    // The first parameter is the name of the cookie, the second is 
    //the value, and the third is the expiry time in seconds.
    setcookie("name", "value", time() + 30 * 24 * 60 * 60); 
    // The echo command is used to print
    echo "Value of the particular name cookie will expire in 30 days"
    // In this case, the cookie  will expire in 30 days
?>


Output:

Value of the particular name cookie will expire in 30 days

Example 2: The following code example will remove all persistent cookies.

PHP




<?PHP
  // remove all persistent cookies
  //setcookie() defines a cookie to be
  //sent along with the other HTTP headers
  
  // The first parameter is the name of the 
  //cookie ie. username, the second is the value 
  //ie. NULL and the third is the expiry time in seconds.
  setcookie('username', '', time()-3600); 
  
  // The first parameter is the name of the cookie
  //ie. password, the second is the value ie. NULL
  //and the third is the expiry time in seconds.
  setcookie('password', '', time()-3600); 
  //Here echo command is used to print
  echo "All persistent cookies are removed"
  // Now, all persistent cookies are removed
?>


Output:

All persistent cookies are removed

Advantages of Persistent Cookie:

  • A persistent cookie remains on a user’s device for the period of time specified in the cookie’s max-age attribute.
  • It can be used to store information about the user, such as the user’s preferences or login status.
  • This makes persistent cookies more useful for tracking users’ Web activities over extended periods of time.
  • Persistent cookies can also be used for purposes such as storing items in a shopping cart or keeping track of a user’s progress through a form.
  • To mitigate this risk, many web browsers provide a mechanism for users to view and delete persistent cookies.
  • This can be useful for websites that offer personalized content or features, such as online stores or social media sites.
  • They can help improve the user experience on a website by storing users’ preferences and settings.

Disadvantages of Persistent Cookie:

  • They take up valuable storage space on a user’s device. They can be used to track a user’s browsing habits and collect data about them.
  • They can expire and become invalid, which can cause problems for users if they rely on them to log in to websites or access certain features.
  • They can be stolen by hackers and used to gain access to a user’s account on a website. They can be used to send spam or malware to a user’s device. They can be used to exploit security vulnerabilities in a user’s browser or device. They can be used to track a user’s location.
  • They can be used to overload a user’s device with cookies, which can slow it down.
  • They can be used to eavesdrop on a user’s browsing habits.
  • They can be used to target ads at a user based on their browsing habits.
  • They can be used to sell a user’s browsing data to third parties.
  • They can be used to bypass privacy settings in a user’s browser.
  • They can be used to launch denial of service attacks against a website.
  •  They can be used to phish a user’s login credentials.
  • They can be used to hijack a user’s session on a website.

Applications of Persistent Cookie:

  • Web servers use persistent cookies to identify individual users and understand their prior activity. This allows the server to tailor the web experience to the user by displaying content that reflects their preferences.
  • Persistent cookies can also store data such as login credentials, online shopping cart items, and preferences. This allows users to avoid having to re-enter this information every time they visit a website.
  • They are used for session management, to keep track of a user’s progress through a website.
  • They can be used for personalization, to store information about a user’s preferences and interests.
  • They can be used for security, to store information that can be used to authenticate a user, or to track a user’s activity on a website.
  • They can be used to record which websites users visit and for how long, which can be used to build up a profile of users’ interests and browsing habits.
  • They can be used to store information about a user’s social media activity and to provide targeted content and advertisements to a user.
  • They can store information about a user’s search history and provide targeted search results to a user.
  • They can store information about a user’s purchase history and provide targeted content and advertisements to a user.
  • They can also store information about a user’s location and provide targeted content and advertisements to a user.
  • They can also be used to keep items in an online shopping cart on an e-commerce website.


Last Updated : 19 Sep, 2022
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads