4

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...

4
  • Are the cookies of the same origin?
    – mradcliffe
    Commented Apr 28, 2016 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
    Commented Apr 29, 2016 at 5:24
  • See if this applies to your situation: developer.mozilla.org/en-US/docs/Web/Security/…
    – mradcliffe
    Commented Apr 29, 2016 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
    Commented Mar 1, 2019 at 23:26

1 Answer 1

1

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

if (isset($_COOKIE['cookie_name'])) {
  print($_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!

8
  • 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 Commented Sep 13, 2016 at 13:50
  • 1
    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. Commented Sep 14, 2016 at 14:53
  • I think that you need to improve your question, maybe with an explanation about why this is the good solution Commented Sep 14, 2016 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. Commented Sep 14, 2016 at 14:56
  • My opinion is that you should encourage good responses not take away people's binge. Commented Sep 14, 2016 at 14:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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