Cookie question - more information in one cookie

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Cookie question - more information in one cookie

Post by JKM »

Isn't it possible to save more information that one line in a cookie?
line1: name
line2: pw
line3: some security check

And have it like this:
$_COOKIE['mypage_cookie']['name']
$_COOKIE['mypage_cookie']['pass']
$_COOKIE['mypage_cookie']['hash']

If so, how do I solve it? Thanks.
User avatar
Peter Anselmo
Forum Commoner
Posts: 58
Joined: Wed Feb 27, 2008 7:22 pm

Re: Cookie question - more information in one cookie

Post by Peter Anselmo »

All cookies are simply key/value pairs. You would need to create a separate cookie for each value.

Does your user have separate logins for different pages on your site? If not, why not just change this:

Code: Select all

$_COOKIE['mypage_cookie']['name']
$_COOKIE['mypage_cookie']['pass']
$_COOKIE['mypage_cookie']['hash']
to this:

Code: Select all

$_COOKIE['name']
$_COOKIE['pass']
$_COOKIE['hash']
User avatar
Darhazer
DevNet Resident
Posts: 1011
Joined: Thu May 14, 2009 3:00 pm
Location: HellCity, Bulgaria

Re: Cookie question - more information in one cookie

Post by Darhazer »

Alternatively, you can serialize array to set it as a cookie's value, and unserialize it when you read it.
Post Reply