How can I save multiple variables in one cookie using PHP?
-
I have variables in php for example: $article_id; $article_title; $article_description; $news_id; $news_headline; $news_description; I want to save all these variables in one cookie. Thankyou.
-
Answer:
You have two options. 1) character delimit the variables like: $cookieValue = "$article_id|$article_title"; 2) Put them in an array and serialize it, to be unserialzed when you read the cookie: $array[]=$article_id; $array[]=$article_title; //... $cookieValue=serialize($array);
Manish at Yahoo! Answers Visit the source
Other answers
Would't it be smarter to save these cookies in a database? Then you'd only need to save the article and news id. I can imagine how fat cookies will get using your solution..
ZahirJ
Zahir is correct. It is old school to stuff multiple {name/value} pairs into a single client side cookie that are either serialized or delimited. A better approach is to simply store a single ID number in the cookie which matches a DB record for the vistor. Then the DB can keep relational data. Each time they visit, retrieve their ID from the cookie and propagate a session object with their prefs. When they change something, just update the DB record. If they are willing to create creat and ID or give you their email address (doesn't have to be a login account) they you can associate that with their ID. Then if they clear their cookies or go to another computer, they can get all their prefs back.
Railgun
Related Q & A:
- How can I save an Icollection in an object?Best solution by Stack Overflow
- How can I pass global variables into a function?Best solution by Stack Overflow
- How can I extract data of an external XML to PHP?Best solution by Stack Overflow
- How can I save photo attachments to Yahoo! Photos in mail beta?Best solution by ph.answers.yahoo.com
- How can I save money when I shopping at walmart?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.