phpcookiesdrupaldrupal-7pantheon

PHP cookie set within Drupal inaccessible in non-Drupal script


I'm setting a cookie within a Drupal app that's hosted on Pantheon (let's just say the URL is domain.com/step/1) immediately before redirecting to an external URL like this:

$expires = time()+(60*60*24);
setrawcookie('tourPath', '/step/1', $expires, '/');
header('Location: http://www.someexternalurl.com?redirect='.$callback_url);

The external URL handles the request in a way that isn't really relevant to this question, but it then redirects to $callback_url. Let's say it's domain.com/callback. Regardless, it's on the same domain, but it's just a plain PHP script (not within Drupal).

The problem I'm having here is that when the redirect to the callback script happens, I can see in my browser that the tourPath cookie is set, but it's not in the $_COOKIE array.

I can see various Drupal cookies in $_COOKIE, so there isn't some problem with setting cookies in general.

I tried using setcookie() instead, but that didn't help.


Solution

  • When dealing with pantheon and setting your own cookies/session vars you'll need to prepend the cookie name with "SESS" according to their docs here:

    https://pantheon.io/docs/articles/sites/varnish/caching-advancedtopics/

    So instead of:

    setcookie('hi', 'howareyou?');
    

    You'll need to use:

    setcookie('SESShi', 'howareyou?');