newbie: cookie values

This is a discussion on newbie: cookie values within the alt.comp.lang.php forums, part of the PHP Programming Forums category; Hey I'm developing a web site using php 5.2.0 Is it possible to store more than one ...


Go Back   Usenet Forums > PHP Programming Forums > alt.comp.lang.php

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-04-2007
Jeff
 
Posts: n/a
Default newbie: cookie values

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


Reply With Quote
  #2 (permalink)  
Old 01-04-2007
Gleep
 
Posts: n/a
Default Re: newbie: cookie values

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

Reply With Quote
Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 12:04 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0