I would like to check whether a Cookie exists, and if so, get the value. But it looks like Drupal is blind to external cookies that have not been set inside Drupal.

$mycookie = \Drupal::request()->cookies->all();

Returns an array with only the Drupal cookies, and I can see in my web browser that there are more (some that I am interested in and I can't modify he app that is creating those cookies). I remember there was a similar issue with Symfony 2 and session but I can't find it...

  • Are the cookies of the same origin? – mradcliffe Apr 28 '16 at 11:39
  • @mradcliffe They are created in a different host than the one I have Drupal running, (they are actually Mautic cookies and I'm trying to to do that "mautic.org/community/index.php/2985-get-data-from-mautic/0" - oh wow now I realize I might have asked in the wrong place or wrong question...) Is it possible to get those cookies? – Cesc Apr 29 '16 at 5:24
  • See if this applies to your situation: developer.mozilla.org/en-US/docs/Web/Security/… – mradcliffe Apr 29 '16 at 10:12
  • 2
    I'm voting to close this question as off-topic because this is nothing Drupal-specific. You can always only access cookies from the same origin. You can't access cookies from other origins. Imagine if that were possible. I could then write a web application that would harvest your gmail cookies, and log into your gmail remotely to do whatever I like. – leymannx Mar 1 '19 at 23:26

For external cookies please try with $_COOKIE['cookie_name'].

if (isset($_COOKIE['cookie_name'])) {

The code will print out the value of the cookie if present.

For a more specific answer please explain your question.Ty!

| improve this answer | |
  • 2
    This does not provide an answer to the question. Once you have sufficient reputation you will be able to comment on any post; instead, provide answers that don't require clarification from the asker. - From Review – Adrian Cid Almaguer Sep 13 '16 at 13:50
  • Please see the first sentence:"I would like to check whether a Cookie exists, and if so, get the value." The: $_COOKIE['cookie_name'] will return the value if exits. Also there is no clear question here, and no question mark. It is very easy to put -1. – Arnold PÉTER Sep 14 '16 at 14:53
  • I think that you need to improve your question, maybe with an explanation about why this is the good solution – Adrian Cid Almaguer Sep 14 '16 at 14:55
  • I not the downvoter but I'm sure that the downvote was because this site is for learning, and you need to explain a little your answer. – Adrian Cid Almaguer Sep 14 '16 at 14:56
  • My opinion is that you should encourage good responses not take away people's binge. – Arnold PÉTER Sep 14 '16 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.