<p>Try <a href="https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/HttpRequestService.php#L893" rel="nofollow">deleteCookie()</a> in HttpRequestService?</p>

CC BY-SA 3.0
2016-02-04T20:43:22.640Z
Thanks khalwat, that pointed me in the right direction. I've also [updated my other question](http://craftcms.stackexchange.com/questions/13478/how-can-i-get-check-the-contents-of-a-cart-via-javascript-cookie/) that is related to this for anyone who comes across this question.
Damon
CC BY-SA 3.0
2016-02-04T03:56:14.070Z
2016-02-04T03:56:14.070Z
andrew.welch
<p>I wasn't able to find an answer for removing a cookie in Craft 3 so after plenty of time of trying to figuring it out, this is my conclusion. </p>

<p>First of all, I am setting the cookie using the following method.</p>

<pre><code>$cookie = new Cookie(['name' =&gt; 'cookieName']);
$cookie-&gt;value = $data['accessToken'];
$cookie-&gt;expire = $data['expires'];
Craft::$app-&gt;getResponse()-&gt;getCookies()-&gt;add($cookie);
</code></pre>

<p>I kept running into a problem with the Cookies being set are read-only so in order to remove the cookie need to use response to change and remove cookies.</p>

<pre><code>Craft::$app-&gt;response-&gt;cookies-&gt;remove('cookieName');
</code></pre>

CC BY-SA 4.0
2020-02-18T15:38:46.680Z
Thank you Jamie worked perfectly
José Veríssimo
CC BY-SA 4.0
2020-02-18T15:36:45.377Z
2020-02-18T15:36:45.377Z
Jamie Hunt
<p>I am able to set a plain old cookie like this:</p>

<pre><code>$cookie = new HttpCookie('myCookie', 'myValue');
</code></pre>

<p>I am trying to delete it like this:</p>

<pre><code>$cookie = new HttpCookie('myCookie', '');
craft()-&gt;request-&gt;getCookies()-&gt;add($cookie-&gt;name, $cookie);
</code></pre>

<p>When I make a call to check the cookie, I get this returned:</p>

<pre><code>{"name":"myCookie","value":"","domain":"","expire":0,"path":"\/","secure":false,"httpOnly":true}
</code></pre>

<p>I can see that the value is getting cleared, but is there any way to just totally wipe out the cooke?</p>

<plugin-development><cookies>
How can I delete a cookie from a plugin?
# How can I delete a cookie from a plugin?

(Asked by: username_0 on 2016-02-04)

I am able to set a plain old cookie like this:
$cookie = new HttpCookie('myCookie', 'myValue');

I am trying to delete it like this:
$cookie = new HttpCookie('myCookie', '');
craft()->request->getCookies()->add($cookie->name, $cookie);

When I make a call to check the cookie, I get this returned:
{"name":"myCookie","value":"","domain":"","expire":0,"path":"\/","secure":false,"httpOnly":true}

I can see that the value is getting cleared, but is there any way to just totally wipe out the cooke?

**Tags:** plugin-development, cookies


---

## 2 answers

### Answer by username_1 on 2016-02-04. Score: 1 | Accepted answer

Try [deleteCookie()](https://github.com/pixelandtonic/Craft-Release/blob/master/app/services/HttpRequestService.php#L893) in HttpRequestService?

> **Comments:**
> **username_0**: Thanks khalwat, that pointed me in the right direction. I've also [updated my other question](http://craftcms.stackexchange.com/questions/13478/how-can-i-get-check-the-contents-of-a-cart-via-javascript-cookie/) that is related to this for anyone who comes across this question.  

---

### Answer by username_2 on 2020-02-18. Score: 2

I wasn't able to find an answer for removing a cookie in Craft 3 so after plenty of time of trying to figuring it out, this is my conclusion. 
First of all, I am setting the cookie using the following method.
$cookie = new Cookie(['name' => 'cookieName']);
$cookie->value = $data['accessToken'];
$cookie->expire = $data['expires'];
Craft::$app->getResponse()->getCookies()->add($cookie);

I kept running into a problem with the Cookies being set are read-only so in order to remove the cookie need to use response to change and remove cookies.
Craft::$app->response->cookies->remove('cookieName');

> **Comments:**
> **username_3**: Thank you Jamie worked perfectly  

---

