Recur
Recur

Reputation: 1428

Cookie data not accessible from another page

I'll try to simplify this as much as possible and add details if needed.

I have two pages: page A and page B.

page A has drupal included and I'm logged in. page B doesn't have the drupal includes so I'm not logged in.

In page A, I save a string to the session/cookie variable and then I post to page B.

In page B I want to retrieve the info from the session/cookie variable but if I do var_dump on those two variables in page B it shows nothing.

How can I make it so that I can get the information I saved from page A's session/cookie variable in to page B's session/cookie variable?

edit: I've done some further testing and concluded it must be drupal messing with the cookies - I created pages on the same server except not in drupal's directory.. just regular php pages. I create a cookie in page A and use jquery's post to go to page B and I get back the cookie information.

This did not work in my drupal-ized page A to non-drupal page B example I stated originally.

I've also tried to change the cookie_domain in drupal's settings.php but that did not help either. I'm at a loss as to what I can do now. Does anyone have suggestions?

Upvotes: 0

Views: 2949

Answers (1)

Recur
Recur

Reputation: 1428

Found the issue!

http://php.net/setcookie

I had to set the path variable to root

( e.g.: setcookie("TestCookie", $value, time()+3600, "/") )

in order for the cookie to be read from another page on the same server but not in the same directory.

Now that I set the cookie to be in root, all pages on the server have access to that cookie!

tl;dir: Cookie info set in one directory won't necessarily be seen by a page requesting that cookie info from another directory so set the cookie's path to root or the appropriate directory so info can be passed around.

Upvotes: 4

Related Questions