0

Is it possible to set/get cookies between php and javascript?

I tried two cases:

  • setCookie on Javascript, and then getCookie on PHP, it works
  • setCookie on PHP, and getCookie on Javascript, then it failed, always return null.

I am wondering if it is supposed to work in this way?

5
  • stackoverflow.com/questions/4003823/… Commented Jul 8, 2013 at 5:57
  • Thanks Dasun, But I don't think that what I want Commented Jul 8, 2013 at 6:18
  • Oh I thought you are following W3Schools and Having ann issue Commented Jul 8, 2013 at 6:19
  • Could you please provide some sourceCode? Commented Jul 8, 2013 at 8:43
  • Hi, Chris. In my PHP page, I use this to setCookie: setcookie($GLOBAL_COOKIE_KEY_CREATED_CV_THEME_ID, $param_themeId, time()+$GLOBAL_COOKIE_EXPIREDAYS, '/'); Commented Jul 9, 2013 at 1:49

1 Answer 1

0

I think the issue was, my php folder is under a different directory apart from html page.

I went through the php documentation about cookies, and found out that Cookies can be saved for specific page which is depending on the path you specified.

What I did changed right now is specify the path as '/', so the cookie will be available for all pages:

setcookie($GLOBAL_COOKIE_KEY_CREATED_CV_THEME_ID, $param_themeId, time()+$GLOBAL_COOKIE_EXPIREDAYS, '/');

Ref: http://us.php.net/setcookie

Hope this could help, but if someone found it's wrong, please comment, thanks.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.