简体   繁体   中英

Get Cookie made with javascript in PHP

I am using JS Cookie.

Cookies.set('cookie1','cookieValue');

Yet in PHP when I try to get the cookie I get NULL

var_dump($_COOKIE['cookie1']);

I can see the cookie in the console and if I run

var_dump($_COOKIE);

I can see all other cookies but not this one (cookie1)

js :

var tempo = 1;   //   data in cookie
document.cookie='cookie='+tempo; 

php :

if (isset($_COOKIE["cookie"])) 
  echo $_COOKIE["cookie"]; 
else 
  echo "Cookie Not Set";

I found the issue. We are using Pantheon and they use Varnish Cache. Varnish was set to only cache certain cookies. We had to add SESS to the beginning of the cookie name and change it from camelCase to snakecase. I am posting this as an answer in case anyone else ever has this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM