|
Posted by Gleep on 01/04/07 18:25
On Thu, 4 Jan 2007 18:09:05 +0100, "Jeff" <it_consultant1@hotmail.com.NOSPAM> wrote:
>Hey
>
>I'm developing a web site using php 5.2.0
>
>Is it possible to store more than one value in a cookie or must I create one
>cookie for each value I want stored?
>
>Lets say I want to store these values in a cookie:
>username = "noob"
>password = "easy"
>ip_address = "127.0.0.1"
>How should I do it?.. I mean should I use setcookie for each value or...
>maybe I can store these values in the session, and then again store the
>session in the cookie?
>
>After a user has logged in I want the cookie to hold info about the user. So
>after restarting the computer or restarting the internet browser the web
>site should recognize the user so he don't need to login again. The use must
>login again when the cookie expire or after the user has logout.
>
>Any suggestions???
>
>Jeff
>
You can take an array of values then serialize it, then save the serialzed value in the cookie
when you need it back, get the cookie value and unserialize the sting back into an array.
But be aware there is a limit how much data a cookie can save. I'd say you'd be save with 10 values
in the array, but if you need to save more than that, your going to have adjust your code and save
the values into a db.
I ran into this problem when I needed to save the values of search matches. I originaly saved it to
a cookie so I can have a unique pagination pattern. I found that my pagination/cookie system no
longer worked after a search with a large number of matches. So I had to abandon the cookie method
and instead set up a random temp session (if user was not logged in) and assign that temp session
ID into a searches table that kept the values of the search. All that clutter builds up during the
day, I set up a cron and clear the search data table out the next morning.
Good luck
[Back to original message]
|