How to save jQuery object in a cookie?

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

Was this solution helpful to you?

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:

Just Added Q & A:

Find solution

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.