Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to encode cookie data

I'm setting a cookie with some query string values for a page I've built, so that when you revisit the page you will have option set for you.

So if the URL is http://mysite.com/index.php?setting1=blue&orientation=horizontal&background=paper the cookie will store the setting1=blue, orientation=horizontal, and background=paper values to be read back on the next visit.

It seems like most people advise json encoding these values prior to storing in the cookie. However, I'm getting way bigger cookie sizes (like 4-5x bigger!) when json encoding vs. just saving these values in a standard query string format and parsing them later.

Any best practice for this situation?

like image 519
julio Avatar asked Jun 17 '26 15:06

julio


1 Answers

Query string format is fine, if it's easy for you to parse them back.

like image 170
alex Avatar answered Jun 19 '26 05:06

alex



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!