2

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.

wp78de
  • 18,207
  • 7
  • 43
  • 71
Ben Chamberlin
  • 671
  • 4
  • 18
  • As a side-note, setting this `tourPath` variable within the callback URL isn't possible due to limitations out of my control on the external service: They require that all redirect URLs get whitelisted, so it would be a huge pain to have to whitelist every single /step/1, /step/2, /step/3, etc... – Ben Chamberlin Nov 25 '15 at 20:58

1 Answers1

3

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?');