DotDragnet
February 08, 2012, 10:20:27 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: follow us on twitter @dotdragnet
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: cookies and not the chocolate ones  (Read 750 times)
SLEE
Hero Member
*****
Posts: 816



View Profile WWW Awards
« on: February 27, 2010, 07:06:19 PM »

right im dabbling with some php and I need to store some values in a cookie.
i will need to set 5 sets of values with 4 values for each set.
what is the best way to store them in a cookie?
should i set a different cookie for each set?
is there a limit to the amount of data you can store in a cookie?
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
sarahA
DDN Contribs
Hero Member
*****
Posts: 2123



View Profile WWW Awards
« Reply #1 on: February 27, 2010, 09:08:31 PM »

Sounds like you want to use an array.

The limit on size is down to the browser. Couldn't say what the limit it. Easiest way is to test it yourself smile
Logged

SLEE
Hero Member
*****
Posts: 816



View Profile WWW Awards
« Reply #2 on: February 27, 2010, 09:41:51 PM »

thanks will do.
One further question, ive set up the cookie with one option for now to test it but when i click a link to activate it i need the page to refresh for it to work. i can use javascript but id rather not use that if i can.
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
JasonD
Global Moderator
Hero Member
*****
Posts: 529



View Profile Awards
« Reply #3 on: February 28, 2010, 02:35:56 PM »

Cookies will be limited to the usable length of a http header (depends on server and browser, no limits are set by HTTP). All cookies share the same line, so one cookie or four cookies would make little difference.

This sort of thing is what sessions were made for.
Logged
SLEE
Hero Member
*****
Posts: 816



View Profile WWW Awards
« Reply #4 on: February 28, 2010, 10:24:46 PM »

thanks Jason I managed to sort it out, i used one cookie and stored only what was needed at the time in the cookie which i should of thought about in the first place. one thing I have noticed though is that setting a cookie and reading it immediately does not always work so i think i need to do as you say and use a session and use the cookie for when the user comes back.
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
JasonD
Global Moderator
Hero Member
*****
Posts: 529



View Profile Awards
« Reply #5 on: February 28, 2010, 11:13:24 PM »

$_COOKIE is set from the request and not updated, but there is nothing stopping you from doing $_COOKIE['foo'] = 'bar' along with setcookie('foo', 'bar') if you feel the need.
Logged
SLEE
Hero Member
*****
Posts: 816



View Profile WWW Awards
« Reply #6 on: March 01, 2010, 01:14:04 PM »

Jason that was exactly what i needed! by using $_COOKIE['foo'] = 'bar' as well it works perfectly smile
Logged

SLEE - still the most confusing ddner...

Follow me on Twitter
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!