English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

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.

2006-07-23 02:53:48 · 3 answers · asked by Manish 5 in Computers & Internet Programming & Design

well, the cookies won'tbe that fat, because the whole news or article is not saved in the cookie, only a few characters to display in the table and when user clicks on <> link, can view full news and/or article which is read from the DB.

2006-07-23 05:02:11 · update #1

3 answers

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);

2006-07-23 03:03:03 · answer #1 · answered by John J 6 · 1 0

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.

2006-07-23 04:35:04 · answer #2 · answered by Anonymous · 0 0

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..

2006-07-23 03:50:33 · answer #3 · answered by ZahirJ 2 · 0 0

fedest.com, questions and answers