Answers.Body: <p>Craft uses Yii's cookie handling, which includes <a href="https://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies#cookie-validation" rel="nofollow noreferrer">cookie validation</a>, resulting in cookies being signed with a hash string. To retrieve a plaintext (unvalidated) cookie, use PHP's global variable  <code>$_COOKIE</code>.</p>
  <pre class="lang-php prettyprint-override"><code>$value = $_COOKIE['downloads-1'] ?? null;
  </code></pre>
  <p>From your screenshot, it looks like something unrelated created a session cookie of the same name. Look at the path to start troubleshooting where it might have been set.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-26T08:08:42.623Z
Answers.LastActivityDate: 2022-07-26T08:08:42.623Z
Answers.UserDisplayName: Ben Croker
Body: <p>In the frontend my website sets a cookie wich i need during a controller action. When calling the controller action from my plugin this Cookie gets duplicated and the value is replaced with an identifier.</p>
  <p>BEFORE CALLING CONTROLLER:
  <a href="https://i.sstatic.net/LV6Q3.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/LV6Q3.png" alt="enter image description here" /></a></p>
  <p>DURING CONTROLLER ACTION:
  <a href="https://i.sstatic.net/sNA3u.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sNA3u.png" alt="enter image description here" /></a></p>
  <p>As seen in the screenshot above the original json value of the Cookie is replaces with an integer.
  I have tried different methods to get the cookie but no success.</p>
  <pre><code>Cookies::$plugin-&gt;cookies-&gt;get(&quot;downloads-1&quot;) \\Returns 1649671559
  Craft::$app-&gt;request-&gt;cookies-&gt;get(&quot;downloads-1&quot;) \\Returns null
  $_COOKIE[&quot;downloads-1&quot;] \\Returns 1649671559
  
  </code></pre>
  <p>How can I get the original value of my cookie in my controller?</p>
  <p><strong>System</strong> <br />
  PHP version 7.4.16 <br />
  Craft edition &amp; version Craft Pro 3.7.27.2</p>
  
Tags: <craft3><plugin-development><controller><cookies>
Title: Can't access Cookie from controller in plugin
ThreadText: # Can't access Cookie from controller in plugin
  
  (Asked by: username_0 on 2022-04-11)
  
  In the frontend my website sets a cookie wich i need during a controller action. When calling the controller action from my plugin this Cookie gets duplicated and the value is replaced with an identifier.
  
  BEFORE CALLING CONTROLLER:
  [![enter image description here](https://i.sstatic.net/LV6Q3.png)](https://i.sstatic.net/LV6Q3.png)
  
  DURING CONTROLLER ACTION:
  [![enter image description here](https://i.sstatic.net/sNA3u.png)](https://i.sstatic.net/sNA3u.png)
  
  As seen in the screenshot above the original json value of the Cookie is replaces with an integer.
  I have tried different methods to get the cookie but no success.
  
  ```
  Cookies::$plugin->cookies->get("downloads-1") \\Returns 1649671559
  Craft::$app->request->cookies->get("downloads-1") \\Returns null
  $_COOKIE["downloads-1"] \\Returns 1649671559
  
  ```
  
  How can I get the original value of my cookie in my controller?
  
  **System**   
  PHP version 7.4.16   
  Craft edition & version Craft Pro 3.7.27.2
  
  **Tags:** craft3, plugin-development, controller, cookies
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-07-26. Score: 1
  
  Craft uses Yii's cookie handling, which includes [cookie validation](https://www.yiiframework.com/doc/guide/2.0/en/runtime-sessions-cookies#cookie-validation), resulting in cookies being signed with a hash string. To retrieve a plaintext (unvalidated) cookie, use PHP's global variable `$_COOKIE`.
  
  ```php
  $value = $_COOKIE['downloads-1'] ?? null;
  
  ```
  
  From your screenshot, it looks like something unrelated created a session cookie of the same name. Look at the path to start troubleshooting where it might have been set.
  
  
  ---
  
  