<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Cookies Archives - scmGalaxy</title>
	<atom:link href="https://www.scmgalaxy.com/tutorials/tag/cookies/feed/" rel="self" type="application/rss+xml" />
	<link>https://www.scmgalaxy.com/tutorials/tag/cookies/</link>
	<description>A Platform for Software Engineers</description>
	<lastBuildDate>Sat, 21 Feb 2026 07:13:34 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=7.1</generator>
	<item>
		<title>Understanding Cookies: Concepts, Use Cases, Architecture and Getting Started</title>
		<link>https://www.scmgalaxy.com/tutorials/understanding-cookies-concepts-use-cases-architecture-and-getting-started/</link>
					<comments>https://www.scmgalaxy.com/tutorials/understanding-cookies-concepts-use-cases-architecture-and-getting-started/#respond</comments>
		
		<dc:creator><![CDATA[Vijay K]]></dc:creator>
		<pubDate>Fri, 30 May 2025 18:24:00 +0000</pubDate>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Backend]]></category>
		<category><![CDATA[CCPA]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Frontend]]></category>
		<category><![CDATA[GDPR]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[Privacy]]></category>
		<category><![CDATA[SessionManagement]]></category>
		<category><![CDATA[UserExperience]]></category>
		<category><![CDATA[WebAnalytics]]></category>
		<category><![CDATA[WebDevelopment]]></category>
		<category><![CDATA[WebSecurity]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=12496</guid>

					<description><![CDATA[<p>What Are Cookies? Cookies are small text files that web servers send to a user’s web browser, which stores them [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/understanding-cookies-concepts-use-cases-architecture-and-getting-started/">Understanding Cookies: Concepts, Use Cases, Architecture and Getting Started</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<figure class="wp-block-image size-large"><img fetchpriority="high" decoding="async" width="1024" height="683" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-6-1024x683.png" alt="" class="wp-image-12501" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-6-1024x683.png 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-6-300x200.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-6-768x512.png 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-6.png 1536w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">What Are Cookies?</h2>



<p class="wp-block-paragraph">Cookies are small text files that web servers send to a user’s web browser, which stores them on the client’s device. These files contain data that help websites remember information about users, such as login status, preferences, or tracking identifiers.</p>



<p class="wp-block-paragraph">Cookies were introduced in the early 1990s to address the challenge posed by the HTTP protocol’s statelessness — meaning that each request to a server is independent and does not inherently carry information about previous interactions. Cookies allow websites to “remember” users and their interactions across sessions.</p>



<p class="wp-block-paragraph">Each cookie consists of key-value pairs and a set of metadata that define the cookie’s scope, lifespan, and security properties. The browser automatically includes relevant cookies in subsequent HTTP requests to the appropriate domains, enabling servers to maintain a continuous user experience.</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading">Major Use Cases of Cookies</h2>



<p class="wp-block-paragraph">Cookies are vital across many web application domains due to their ability to persist state and track information. Below are key use cases:</p>



<h3 class="wp-block-heading">1. <strong>Session Management</strong></h3>



<p class="wp-block-paragraph">Cookies enable websites to identify returning users and maintain session continuity without requiring users to authenticate on every page load. For example, after logging in, a session cookie keeps a user logged in until they log out or the session expires.</p>



<h3 class="wp-block-heading">2. <strong>User Preferences and Personalization</strong></h3>



<p class="wp-block-paragraph">Cookies store user settings such as language preferences, theme choices, or layout configurations. When a user revisits, the site can retrieve these preferences and tailor the interface accordingly.</p>



<h3 class="wp-block-heading">3. <strong>Shopping Cart Persistence</strong></h3>



<p class="wp-block-paragraph">E-commerce websites leverage cookies to remember products added to a user’s cart even if the browser is closed and reopened before checkout, enhancing the shopping experience.</p>



<h3 class="wp-block-heading">4. <strong>Tracking and Analytics</strong></h3>



<p class="wp-block-paragraph">Cookies collect data on user behavior, page visits, and navigation paths. Analytics platforms use cookies to generate insights about website performance and user engagement. Advertising networks use third-party cookies to track users across sites for targeted ads.</p>



<h3 class="wp-block-heading">5. <strong>Security</strong></h3>



<p class="wp-block-paragraph">Cookies help secure web applications by storing tokens or flags used in authentication workflows, CSRF protection, and managing user permissions.</p>



<h3 class="wp-block-heading">6. <strong>Legal Compliance</strong></h3>



<p class="wp-block-paragraph">Cookies assist in storing consent information, ensuring compliance with data protection regulations like the General Data Protection Regulation (GDPR) and California Consumer Privacy Act (CCPA).</p>



<hr class="wp-block-separator has-alpha-channel-opacity">



<figure class="wp-block-image size-full"><img decoding="async" width="1024" height="504" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-7.png" alt="" class="wp-image-12502" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-7.png 1024w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-7-300x148.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2025/06/image-7-768x378.png 768w" sizes="(max-width: 1024px) 100vw, 1024px" /></figure>



<h2 class="wp-block-heading">How Cookies Work Along with Architecture</h2>



<p class="wp-block-paragraph">Cookies operate at the intersection of HTTP protocol, client (browser) storage, and server-side application logic. The architecture supporting cookie functionality includes several components:</p>



<h3 class="wp-block-heading">1. <strong>HTTP Headers and Communication</strong></h3>



<ul class="wp-block-list">
<li>When a client sends a request to a server, it includes a <code>Cookie</code> header containing cookies relevant to the request URL’s domain and path.</li>



<li>The server can send back one or more <code>Set-Cookie</code> headers in its response to instruct the browser to store new cookies or update existing ones.</li>
</ul>



<p class="wp-block-paragraph">Example HTTP response header:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
Set-Cookie: sessionId=abc123; Expires=Wed, 09 Jun 2026 10:18:14 GMT; Path=/; Secure; HttpOnly; SameSite=Strict

</pre></div>


<h3 class="wp-block-heading">2. <strong>Browser Cookie Storage</strong></h3>



<ul class="wp-block-list">
<li>Browsers maintain a &#8220;cookie jar&#8221; storing cookies by domain and path.</li>



<li>They enforce scoping rules, ensuring cookies are only sent to appropriate URLs.</li>



<li>Cookies are stored on disk or in memory depending on persistence.</li>
</ul>



<h3 class="wp-block-heading">3. <strong>Cookie Attributes and Their Impact</strong></h3>



<ul class="wp-block-list">
<li><strong>Domain:</strong> Restricts the domains to which the cookie will be sent. Cookies set for <code>example.com</code> are sent to <code>sub.example.com</code> but not to <code>otherdomain.com</code>.</li>



<li><strong>Path:</strong> Restricts the URL paths on the domain for which the cookie is valid.</li>



<li><strong>Expires/Max-Age:</strong> Defines when a cookie will be deleted. Session cookies expire when the browser closes; persistent cookies survive beyond sessions.</li>



<li><strong>Secure:</strong> Ensures cookies are only sent over HTTPS connections.</li>



<li><strong>HttpOnly:</strong> Prevents client-side JavaScript from accessing cookies, mitigating some XSS attacks.</li>



<li><strong>SameSite:</strong> Controls cross-site cookie sharing to prevent CSRF and privacy leaks. Values include <code>Strict</code>, <code>Lax</code>, or <code>None</code>.</li>
</ul>



<h3 class="wp-block-heading">4. <strong>Server-Side Handling</strong></h3>



<ul class="wp-block-list">
<li>Servers read cookies from incoming requests and use their data to maintain sessions, authenticate users, or track state.</li>



<li>Servers can update or delete cookies by sending updated <code>Set-Cookie</code> headers.</li>
</ul>



<h3 class="wp-block-heading">5. <strong>Third-Party Cookies</strong></h3>



<ul class="wp-block-list">
<li>These are cookies set by domains other than the one shown in the browser&#8217;s address bar, typically used by advertisers or analytics services.</li>



<li>Modern browsers are increasingly restricting third-party cookies due to privacy concerns.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading">Detailed Workflow of Cookies</h2>



<h3 class="wp-block-heading">1. <strong>Initial Visit</strong></h3>



<ul class="wp-block-list">
<li>User visits a website; the browser sends a request without cookies.</li>
</ul>



<h3 class="wp-block-heading">2. <strong>Server Response with Cookies</strong></h3>



<ul class="wp-block-list">
<li>Server responds with <code>Set-Cookie</code> headers to establish sessions or preferences.</li>
</ul>



<h3 class="wp-block-heading">3. <strong>Browser Stores Cookies</strong></h3>



<ul class="wp-block-list">
<li>The browser saves cookies respecting domain, path, security attributes.</li>
</ul>



<h3 class="wp-block-heading">4. <strong>Subsequent Requests</strong></h3>



<ul class="wp-block-list">
<li>Browser automatically includes relevant cookies in HTTP requests for that domain/path.</li>
</ul>



<h3 class="wp-block-heading">5. <strong>Server Processes Cookies</strong></h3>



<ul class="wp-block-list">
<li>Server uses cookies to authenticate the user, retrieve session data, or customize the response.</li>
</ul>



<h3 class="wp-block-heading">6. <strong>Cookie Updates</strong></h3>



<ul class="wp-block-list">
<li>Server can update cookies by sending new <code>Set-Cookie</code> headers with modified values or expiration.</li>
</ul>



<h3 class="wp-block-heading">7. <strong>Cookie Expiration or Deletion</strong></h3>



<ul class="wp-block-list">
<li>Cookies expire naturally after their expiry time or are deleted by explicit instructions or user actions.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading">Step-by-Step Getting Started Guide for Cookies</h2>



<h3 class="wp-block-heading">Step 1: Understand Cookie Fundamentals</h3>



<p class="wp-block-paragraph">Familiarize yourself with cookie components — name, value, domain, path, expiry, and security flags.</p>



<h3 class="wp-block-heading">Step 2: Setting Cookies from the Server</h3>



<p class="wp-block-paragraph"><strong>Example: Node.js Express</strong></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
res.cookie(&#039;userId&#039;, &#039;12345&#039;, {
  maxAge: 24 * 60 * 60 * 1000, // 1 day
  httpOnly: true,
  secure: true,
  sameSite: &#039;Strict&#039;,
  path: &#039;/&#039;
});

</pre></div>


<h3 class="wp-block-heading">Step 3: Reading Cookies on Server</h3>



<p class="wp-block-paragraph">Using the <code>cookie-parser</code> middleware:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
const userId = req.cookies.userId;
console.log(`User ID from cookie: ${userId}`);

</pre></div>


<h3 class="wp-block-heading">Step 4: Creating Cookies with JavaScript</h3>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
document.cookie = &quot;theme=dark; max-age=3600; path=/&quot;;

</pre></div>


<h3 class="wp-block-heading">Step 5: Deleting Cookies</h3>



<p class="wp-block-paragraph">Set expiration date in the past:</p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: plain; title: ; notranslate">
document.cookie = &quot;theme=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;&quot;;

</pre></div>


<h3 class="wp-block-heading">Step 6: Implement Security Best Practices</h3>



<ul class="wp-block-list">
<li>Always set <code>HttpOnly</code> and <code>Secure</code> flags where possible.</li>



<li>Use <code>SameSite</code> attributes to reduce CSRF vulnerabilities.</li>



<li>Avoid storing sensitive information directly in cookies.</li>
</ul>



<h3 class="wp-block-heading">Step 7: Respect Privacy Regulations</h3>



<ul class="wp-block-list">
<li>Implement consent banners.</li>



<li>Provide users with options to manage cookie preferences.</li>



<li>Document cookie usage in privacy policies.</li>
</ul>



<hr class="wp-block-separator has-alpha-channel-opacity">



<h2 class="wp-block-heading">Advanced Topics and Considerations</h2>



<h3 class="wp-block-heading">1. <strong>Cookie Size and Limits</strong></h3>



<ul class="wp-block-list">
<li>Most browsers limit individual cookie size to 4KB.</li>



<li>There is a per-domain cookie limit (around 20–50 cookies).</li>



<li>Exceeding limits causes older cookies to be evicted.</li>
</ul>



<h3 class="wp-block-heading">2. <strong>Third-Party Cookie Restrictions</strong></h3>



<ul class="wp-block-list">
<li>Browsers increasingly block or restrict third-party cookies.</li>



<li>Alternatives include localStorage, IndexedDB, or server-side sessions.</li>
</ul>



<h3 class="wp-block-heading">3. <strong>Alternatives to Cookies</strong></h3>



<ul class="wp-block-list">
<li>Web Storage API (localStorage, sessionStorage) for client-side storage.</li>



<li>JWT tokens for stateless authentication.</li>
</ul>



<h3 class="wp-block-heading">4. <strong>Cross-Origin Resource Sharing (CORS) and Cookies</strong></h3>



<ul class="wp-block-list">
<li>Cookies require careful configuration of CORS headers and credentials policies to work across domains.</li>
</ul>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/understanding-cookies-concepts-use-cases-architecture-and-getting-started/">Understanding Cookies: Concepts, Use Cases, Architecture and Getting Started</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/understanding-cookies-concepts-use-cases-architecture-and-getting-started/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What is Cookies and Why it is Used?</title>
		<link>https://www.scmgalaxy.com/tutorials/what-is-cookies-and-why-it-is-used/</link>
					<comments>https://www.scmgalaxy.com/tutorials/what-is-cookies-and-why-it-is-used/#respond</comments>
		
		<dc:creator><![CDATA[Ashwani Kumar]]></dc:creator>
		<pubDate>Wed, 24 May 2023 14:16:25 +0000</pubDate>
				<category><![CDATA[Web Development]]></category>
		<category><![CDATA[Websites]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Different types of cookies]]></category>
		<category><![CDATA[HTTP]]></category>
		<category><![CDATA[HTTP cookies]]></category>
		<category><![CDATA[Magic Cookies]]></category>
		<category><![CDATA[Persistent cookie]]></category>
		<category><![CDATA[Session management]]></category>
		<category><![CDATA[What is Cookies]]></category>
		<category><![CDATA[why cookies are used?]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=10588</guid>

					<description><![CDATA[<p>What is Cookies? Cookies are little text files that websites save on the user&#8217;s device (such as a computer or [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-is-cookies-and-why-it-is-used/">What is Cookies and Why it is Used?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h3 class="wp-block-heading">What is Cookies?</h3>



<p class="wp-block-paragraph">Cookies are little text files that websites save on the user&#8217;s device (such as a computer or mobile device) when the user visits the website. These files include information that the website may download and utilize the next time the visitor visits the site.</p>



<p class="wp-block-paragraph">HTTP cookies are required for modern Internet use, yet they compromise your privacy. HTTP cookies, which are a required aspect of online browsing, assist web developers in providing you with more personalized, easy website visits. Websites may remember you, your website logins, shopping carts, and other information via cookies. They may, however, be a goldmine of private information for crooks to snoop on.</p>



<h3 class="wp-block-heading">Different types of cookies &#8211; Magic Cookies and HTTP Cookies</h3>



<p class="wp-block-paragraph"><strong>Magic cookies</strong> :- The term &#8220;magic cookies&#8221; originated in the early days of computers and describes data packets that are delivered and received unchanged. This is frequently used to enter into computer databases, such a company&#8217;s internal network. The term &#8220;cookie&#8221; as we know it today predates this concept.</p>



<p class="wp-block-paragraph"><strong>HTTP cookies</strong> :- HTTP cookies are a modified form of the &#8220;magic cookie&#8221; designed for web browsing. The &#8220;magic cookie&#8221; inspired web browser creator Lou Montulli in 1994. When he assisted a website for online shopping in repairing its overburdened servers, he duplicated this idea for browsers.</p>



<h3 class="wp-block-heading">What Are Cookies Used For?</h3>



<figure class="wp-block-image size-large"><img decoding="async" width="869" height="1024" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131-869x1024.png" alt="" class="wp-image-10591" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131-869x1024.png 869w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131-255x300.png 255w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131-768x905.png 768w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131-1303x1536.png 1303w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-131.png 1500w" sizes="(max-width: 869px) 100vw, 869px" /></figure>



<p class="wp-block-paragraph">Websites utilize HTTP cookies to improve the user experience. Without cookies, you would have to log back in each time you left a website or, if you accidently closed the browser, rebuild your shopping cart. making cookies a crucial component of using the internet.</p>



<p class="wp-block-paragraph"><strong>Session management :-</strong> Transient cookies and per-session cookies are other names for session cookies. While a person is browsing a website, session cookies save data. Once the user ends the session, these cookies are removed.</p>



<p class="wp-block-paragraph"><strong>Persistent cookie :-</strong> Cookies that are persistent are kept for a certain period of time. Until they are erased or they expire, these cookies stay on your device. Because they are used to gather user data including browsing patterns and preferences, persistent cookies are also known as tracking cookies.</p>



<p class="wp-block-paragraph"><strong>First-party and third-party cookies :-</strong> Cookies that are set by websites that users visit directly are known as first-party cookies. These cookies typically store data relevant to or related with the website, such as user preferences or location.<br>Cookies that are associated with third-party content, such as embedded videos, advertisements, web banners, and scripts, are referred to as third-party cookies. Third-party cookies are frequently used by advertisers to monitor user behaviour.</p>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="803" height="606" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-130.png" alt="" class="wp-image-10590" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-130.png 803w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-130-300x226.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2023/05/image-130-768x580.png 768w" sizes="auto, (max-width: 803px) 100vw, 803px" /></figure>



<p class="wp-block-paragraph"><strong>Tracking :-</strong> Shopping sites use cookies to keep track of the items that users have previously viewed, allowing the sites to propose more things that they may be interested in and store products in their shopping carts while customers browse elsewhere.</p>



<h3 class="wp-block-heading">Conclusion </h3>



<p class="wp-block-paragraph">Unsecured cookies may potentially provide a security risk to website owners and users. The original website or a third party receives unencrypted data about an insecure cookie over HTTP. That&#8217;s a low danger if the information is something straightforward, like if the person has already visited the site. Some websites, however, may use cookies to store user data, including personally identifying information such as login passwords and payment card details. Unencrypted transmissions of such kind of data leave them open to interception and misuse by criminals. A secure cookie only permits the transmission of cookie data via HTTPS and does not carry the same danger.</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-is-cookies-and-why-it-is-used/">What is Cookies and Why it is Used?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/what-is-cookies-and-why-it-is-used/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Replace/Append Cookies in JavaScript</title>
		<link>https://www.scmgalaxy.com/tutorials/replace-append-cookies-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/replace-append-cookies-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Sat, 14 Aug 2021 12:56:29 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Append]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[Replace]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7957</guid>

					<description><![CDATA[<p>Replace/Append Cookies When we assign a new cookie value to document.cookie, the current cookie is not replaced. The new cookie [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/replace-append-cookies-in-javascript/">Replace/Append Cookies in JavaScript</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h2 class="wp-block-heading"><strong>Replace/Append Cookies</strong></h2>



<p class="wp-block-paragraph">When we assign a new cookie value to document.cookie, the current cookie is not replaced. The new cookie is parsed and its name-value pair is appended to the list. The exception is when you assign a new cookie with the same name (and same domain and path, if they exist) as a cookie that already exists. In this case, the old value is replaced with the new.</p>



<script src="https://gist.github.com/vijaypk376/446d251d1474e260e3353013eb9b8871.js"></script>



<script src="https://gist.github.com/vijaypk376/d6f9c779cd7e06d9db6bacafcefc4f7f.js"></script>



<h2 class="wp-block-heading"><strong>Reading Cookie</strong></h2>



<p class="wp-block-paragraph">We can read cookies by a document.cookie. The problem occurs when we need the specific part of the cookie to perform some action.</p>



<script src="https://gist.github.com/vijaypk376/1cd4305d71987896e26f5a77beaabb73.js"></script>



<h2 class="wp-block-heading"><strong>Deleting Cookies</strong></h2>



<p class="wp-block-paragraph">A cookie is deleted by setting a cookie with the same name (and domain and path, if they were set) with an expiration date in the past and if using max-age then must set a negative value.</p>



<p class="wp-block-paragraph">Ex: <strong>&#8211;</strong></p>



<script src="https://gist.github.com/vijaypk376/41404c6b09198948b4505ae95d4b4572.js"></script>



<h2 class="wp-block-heading"><strong>Updating Cookies</strong></h2>



<p class="wp-block-paragraph">A cookie is possible to update by setting a new value to a cookie with the same name.</p>



<script src="https://gist.github.com/vijaypk376/d2c0fe84f70231bd257c4ae0eef4bac0.js"></script>



<h2 class="wp-block-heading"><strong>Cookies Security Issues</strong></h2>



<ul class="wp-block-list"><li><strong>Can misuse Client Details</strong></li><li><strong>Can track User</strong></li><li><strong>Client Can Delete Cookies</strong></li><li><strong>Client can Manipulate Cookies</strong></li></ul>



<h2 class="wp-block-heading"><strong>Cookies Limitation</strong></h2>



<ul class="wp-block-list"><li><strong>Support HTML4 / HTML 5</strong></li><li><strong>Each cookie can contain 4kb Data</strong></li><li><strong>Cookies can be stored in Browser and server</strong></li><li><strong>It is sent with each request</strong></li></ul>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/replace-append-cookies-in-javascript/">Replace/Append Cookies in JavaScript</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/replace-append-cookies-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>How many create cookies in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/how-many-create-cookies-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/how-many-create-cookies-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Sat, 14 Aug 2021 12:39:32 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[chrome]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[document object]]></category>
		<category><![CDATA[Google]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[property]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7946</guid>

					<description><![CDATA[<p>JavaScript Cookies Cookies are exposed as the cookie property of the Document object. This property is both readable and writeable. [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-many-create-cookies-in-javascript/">How many create cookies in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading"><strong>JavaScript Cookies</strong></h1>



<p class="wp-block-paragraph">Cookies are exposed as the cookie property of the Document object. This property is both readable and writeable.</p>



<p class="wp-block-paragraph">You can see Cookies in Google Chrome by following chrome://settings/content/cookies</p>



<h1 class="wp-block-heading"><strong>Creating Cookies</strong></h1>



<p class="wp-block-paragraph">When you assign a string to document.cookie, the browser parses it as a cookie and adds it to its list of cookies. There are several parts to each cookies, many of them optional.</p>



<h2 class="wp-block-heading"><strong>Syntax: &#8211;</strong></h2>



<p class="wp-block-paragraph" id="block-0bbc4906-32da-4254-a4a7-5076d7e5c92b">document.cookie = “name=value”;<br>document.cookie = “name=value; expires=date; domain=domain; path=path; secure”;<br>document.cookie = “name=value; max-age=inSecond; domain=domain; path=path; secure”;</p>



<h2 class="wp-block-heading">Ex:-</h2>



<script src="https://gist.github.com/vijaypk376/67579ff638772d712da0e0b9f9596bc1.js"></script>



<h1 class="wp-block-heading"><strong>Creating Cookies</strong></h1>



<p class="wp-block-paragraph"><strong>Optional Cookies Attribute:-</strong></p>



<p class="wp-block-paragraph">max-age<br>expires<br>domain<br>path<br>secure</p>



<p class="wp-block-paragraph">Whenever you omit the optional cookie fields, the browser fills them in automatically with reasonable defaults.</p>



<h2 class="wp-block-heading"><strong>max-age</strong></h2>



<p class="wp-block-paragraph">It is used to create persistent cookies. It is supported by all modern browsers except IE.</p>



<p class="wp-block-paragraph"><strong>Type of cookies: &#8211;</strong></p>



<ul class="wp-block-list"><li>Session Cookies – Cookies that are set without the expires/max-age field are called session cookies. It is destroyed when the user quits the browser.</li><li>Persistent Cookies – The browser keeps it up until their expiration date is reached.</li></ul>



<h2 class="wp-block-heading">Ex:-</h2>



<script src="https://gist.github.com/vijaypk376/f1303dff9cb90e8d60788a9db973d9d8.js"></script>



<h1 class="wp-block-heading"><strong>expires</strong></h1>



<p class="wp-block-paragraph">It is used to create persistent cookies.</p>



<h3 class="wp-block-heading">Type of cookies: &#8211;</h3>



<ul class="wp-block-list"><li>Session Cookies – Cookies that are set without the expires/max-age field are called session cookies. It is destroyed when the user quits the browser.</li><li>Persistent Cookies – The browser keeps it up until their expiration date is reached.</li></ul>



<p class="wp-block-paragraph">E<strong>x:-</strong></p>



<p class="wp-block-paragraph">document.cookie = “username=devops; expires=Monday, 3-Sep-2018 09:00:00 UTC”;</p>



<h1 class="wp-block-heading"><strong>domain</strong></h1>



<p class="wp-block-paragraph">It specifies the domain for which the cookie is valid. If not specified, this defaults to the host portion of the current document location. If a domain is specified, subdomains are always included.</p>



<p class="wp-block-paragraph"><strong>Ex: &#8211;</strong></p>



<script src="https://gist.github.com/vijaypk376/cdde12250b6aee1fcd43e34322d6ed6f.js"></script>



<h1 class="wp-block-heading"><strong>path</strong></h1>



<p class="wp-block-paragraph">Path can be / (root) or /mydir (directory). If not specified, defaults to the current path of the current document location, as well as its descendants.</p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; document.cookie = “username=devops; path=/”;</strong></p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; document.cookie = “username=devops; path=/home”;</strong></p>



<h1 class="wp-block-heading"><strong>secure</strong></h1>



<p class="wp-block-paragraph">Cookie to only be transmitted over secure protocol as https. Before Chrome 52, this flag could appear with cookies from http domains.</p>



<p class="wp-block-paragraph"><strong>Ex: &#8211; document.cookie = “username=devops; secure”;</strong></p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/how-many-create-cookies-in-javascript/">How many create cookies in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/how-many-create-cookies-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>What are cookies in JavaScript?</title>
		<link>https://www.scmgalaxy.com/tutorials/what-are-cookies-in-javascript/</link>
					<comments>https://www.scmgalaxy.com/tutorials/what-are-cookies-in-javascript/#respond</comments>
		
		<dc:creator><![CDATA[rajeshkumar]]></dc:creator>
		<pubDate>Sat, 14 Aug 2021 12:02:52 +0000</pubDate>
				<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[Client]]></category>
		<category><![CDATA[Cookies]]></category>
		<category><![CDATA[Javascript]]></category>
		<category><![CDATA[web server]]></category>
		<guid isPermaLink="false">https://www.scmgalaxy.com/tutorials/?p=7939</guid>

					<description><![CDATA[<p>Cookies A cookie is a small piece of text data set by the Web server that resided on the client’s [&#8230;]</p>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-are-cookies-in-javascript/">What are cookies in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></description>
										<content:encoded><![CDATA[
<h1 class="wp-block-heading">Cookies</h1>



<p class="wp-block-paragraph">A cookie is a small piece of text data set by the Web server that resided on the client’s machine. Once it’s been set, the client automatically returns the cookie to the webserver with each request that it makes. This allows the server to place values it wishes to ‘remember’ in the cookie, and have access to them when creating a response.</p>



<h1 class="wp-block-heading">How Cookie Works</h1>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="756" height="406" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works1.png" alt="" class="wp-image-7940" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works1.png 756w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works1-300x161.png 300w" sizes="auto, (max-width: 756px) 100vw, 756px" /></figure>



<h1 class="wp-block-heading"><strong>How Cookie Works</strong></h1>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="698" height="360" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-2.png" alt="" class="wp-image-7941" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-2.png 698w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-2-300x155.png 300w" sizes="auto, (max-width: 698px) 100vw, 698px" /></figure>



<h1 class="wp-block-heading"><strong>How Cookie Works</strong></h1>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="845" height="294" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-3.png" alt="" class="wp-image-7942" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-3.png 845w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-3-300x104.png 300w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-cookie-works-3-768x267.png 768w" sizes="auto, (max-width: 845px) 100vw, 845px" /></figure>



<h1 class="wp-block-heading"><strong>How Dangerous Cookies are</strong></h1>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="724" height="308" src="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-dangerous-cookies-are.png" alt="" class="wp-image-7943" srcset="https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-dangerous-cookies-are.png 724w, https://www.scmgalaxy.com/tutorials/wp-content/uploads/2021/08/how-dangerous-cookies-are-300x128.png 300w" sizes="auto, (max-width: 724px) 100vw, 724px" /></figure>



<h1 class="wp-block-heading"><strong>Type of Cookies</strong></h1>



<ul class="wp-block-list"><li>Session Cookies – Cookies that are set without the expires field are called session cookies. It is destroyed when the user quits the browser.</li></ul>



<ul class="wp-block-list"><li>Persistent Cookies – The browser keeps it up until their expiration date is reached.</li></ul>
<p>The post <a href="https://www.scmgalaxy.com/tutorials/what-are-cookies-in-javascript/">What are cookies in JavaScript?</a> appeared first on <a href="https://www.scmgalaxy.com/tutorials">scmGalaxy</a>.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://www.scmgalaxy.com/tutorials/what-are-cookies-in-javascript/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
