Drupal中的PHP cookie集在非Drupal脚本中不可访问


PHP cookie set within Drupal inaccessible in non-Drupal script

我正在Pantheon上托管的Drupal应用程序中设置cookie(假设URL为domain.com/step/1),然后立即重定向到这样的外部URL:

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

外部URL处理请求的方式与此问题无关,但它随后重定向到$callback_url。假设它是domain.com/callback。无论如何,它在同一个域上,但它只是一个普通的PHP脚本(不在Drupal中)。

我遇到的问题是,当重定向到回调脚本时,我可以在浏览器中看到tourPath cookie已设置,但它不在$_cookie数组中

我可以在$_COOKIE中看到各种Drupal COOKIE,所以通常设置COOKIE没有问题。

我试着使用setcookie(),但没有帮助。

在处理万神殿并设置自己的cookie/会话变量时,您需要根据此处的文档在cookie名称前加上"SESS":

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

所以不是:

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

您需要使用:

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