1

Via JavaScript I'm able to store a cookie with JSON.stringify(), which stores a cookie directly as I.e.

'[{"n":"50fb0d0cc1277d182f000002","q":2},{"n":"50fb0d09c1277d182f000001","q":1},{"n":"50fb0d06c1277d182f000000","q":1}]

I'm now passing this through a rest API, where the other endpoint receives then needs to re-corporate into the same cookie key and value on the server end. I do this using PHP's set cookie. I'm able to pass through the vars correctly, however when setting cookie with the JSON value it keeps becoming urldecoded, I'm storing it as a straight string and it still becomes I.e:

%5B%7B%22n%22%3A%2250fb0d9dc1277d1b2f000003%22%2C%22q%22%3A3%7D%5D

Any ideas? why this is storing as a decoded value?

6
  • Keep in mind that I have tried urldecode / jsondecode then back into jsonencode. Commented Jan 27, 2013 at 6:29
  • Give us some code, please. Commented Jan 27, 2013 at 6:32
  • Uh, I mean it's basic javascript set cookie and php set cookie functions... Those are standards. The question is, how do you get PHP to store JSON string directly into a cookie without url-decoding it, just like JavaScript's JSON.stringify function. Commented Jan 27, 2013 at 6:37
  • But this is urlencoded. What happens when you urldecode it with php? Commented Jan 27, 2013 at 6:38
  • Roy, it's still stored as decoded URL. Commented Jan 27, 2013 at 6:38

1 Answer 1

3

I figured this out. PHP setcookie by default encodes value, need to use setrawcookie!

http://php.net/manual/en/function.setrawcookie.php

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.