0

I have parts of my website that are not controlled by drupal that set cookies.

When I access a drupal-run page, my cookies get cleared. I tried to investigate which script does this by placing print_r($_COOKIE) all over the place in html.tpl.php, but no luck.

Anybody know whats happening here and how I could set my own custom cookies with PHP in drupal template files?

cheers

1 Answer 1

1

Please find more about setting cookies using php setcookie function.

As explained in above link, please look into third and fourth params in above function

Path

The path on the server in which the cookie will be available on. If set to '/', the cookie will be available within the entire domain. If set to '/foo/', the cookie will only be available within the /foo/ directory and all sub-directories such as /foo/bar/ of domain. The default value is the current directory that the cookie is being set in.

Domain

The domain that the cookie is available to. Setting the domain to 'www.example.com' will make the cookie available in the www subdomain and higher subdomains. Cookies available to a lower domain, such as 'example.com' will be available to higher subdomains, such as 'www.example.com'. Older browsers still implementing the deprecated » RFC 2109 may require a leading . to match all subdomains.

Please check your code where you are setting cookies matches Drupal Site Domain name and Path where you are trying to access or print them.

You can set cookies in Drupal using user_cookie_save function.

For Example

user_cookie_save(array('key'=>'value'));
print $_COOKIE['Drupal_visitor_key']; //outputs value
1
  • 1
    Just to stress the key points. Drupal won't touch your custom cookies. For some reason they cannot be read on the pages you are concerned with. That implies they are being created in such a way they are not accessible. The path and domain settings are the most likely cause (also consider the security settings). Commented Feb 12, 2015 at 9:48

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