Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 01-03-2006, 03:23 PM cookie question
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
ive been looking at tutorials on cookies and none have answered my question, can you store multiple peices of data on one cookie. all the tuts I have seen only cover using one
__________________
I have the heart of a child, I keep it in a jar on my desk.
Village Idiot is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 01-03-2006, 05:33 PM
0beron's Avatar
Defies a Status

Posts: 1,832
Location: Somewhere else entirely
Trades: 0
There are several choices - you can either a) set multiple cookies, b) squash the data into a string, store it in one cookie and then unsqash it later, or c) use array names for cookies (PHP makes them look like arrays but in fact they are just multiple cookies):
PHP Code:
//multiple cookies
setcookie("foo1","data1");
setcookie("foo2","data2");
setcookie("foo3","data3");

//one cookie
setcookie("foo","1,data1|2,data2|3,data3");

//Array names
setcookie("foo[1]","data1");
setcookie("foo[2]","data1");
setcookie("foo[3]","data1"); 
In the one cookie case when you want to use the data you must pull apart the string with explode() or other string functions. The |s and commas aren't special in any way, they just make it easier to do the pulling apart later.

When you read from the $_COOKIE array, the array name method will mean you have one entry in $_COOKIE called $_COOKIE['foo'] which is itself an array.
__________________
UPDATE 0beron SET talkupation = talkupation + lots WHERE post = 'helpful';

Please login or register to view this content. Registration is FREE
(aka MSN handwriting for forums)
0beron is offline
Reply With Quote
View Public Profile Visit 0beron's homepage!
 
Old 01-03-2006, 10:53 PM
Village Idiot's Avatar
Webmaster Talker

Posts: 535
Trades: 0
ok, the method works, thanks
__________________
I have the heart of a child, I keep it in a jar on my desk.
Village Idiot is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to cookie question
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23210 seconds with 12 queries