I really not getting how to do this
From PHP Manual
Cookies names can be set as array names and will be available to your
PHP scripts as arrays but separate cookies are stored on the user’s
system.
This is okay to me and I got and could use like below
setcookie("cookie[three]", "cookiethree");
setcookie("cookie[two]", "cookietwo");
But this method will create multiple cookies and that is I don’t want
PHP manual also says
Consider explode() to set one cookie with multiple names and
values.
But I did not get how to use explode to set one cookie with multiple names and values?
Please someone explain this.
But not getting this
Cookies are nothing else than a dumb key/value storage system. It’s as simple as that.
It happens that PHP offers a nifty feature on top of that: cookies whose names contain square brackets in the described format will be combined into a single array variable when reading cookies back from PHP. But that’s the only exception, it doesn’t affect the way cookies work and, as you’ve said, it’s a feature you don’t need.
Said that, you only need to think of the cookie value as a whiteboard where you can put anything you want, as long as it’s text. And there’re many PHP functions that allow you to convert exotic stuff like arrays into plain text:
Use your imagination and you’re done 😉
Update: A little remark—I’ve mentioned
serialize()for completeness, but it’s probably not worth the effort since it’d be very complicate to ensure you don’t open the door to code injection.