/ Published in: PHP
This is a great way to save complex objects as cookie values. You can't just json_encode because commas are not legal in cookie values. Remember not to use this for anything too big because cookies have a 4KB limit.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
/** * Author: Andrew Hedges, [email protected] * License: free to use, alter, and redistribute without attribution */ /** * Turn any object (e.g., an array) into a string you can save in a cookie * @param object $obj * @return string */ function cookie_encode($obj) { return $value; } /** * Turn a string encoded by cookie_encode back into an object * @param string $value * @return object */ function cookie_decode($value) { return $value; }