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?

David_Wang
  • 652
  • 9
  • 20

1 Answers1

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.

David_Wang
  • 652
  • 9
  • 20