You either need to:
1) Set multiple cookies for each index:

2) Serialize/unserialize your array.

setCookie('session', serialize($session_array) );

$session = unserialize($_COOKIE['session']);


Tom Woody wrote:
Did a google and archive search but I couldn't find anything related...

I am migrating a bunch of perl CGI apps to PHP.
In one of the perl pages a cookie is set and the value of the cookie is
a perl hash. I am trying to duplicate that cookie in PHP to make my
life 100 times easier.

In perl:
use CGI::Cookie;
$session{value1} = "something";
$session{value2} = "else";

In another perl script: use CGI;
$query = CGI->new();
%session = $query->cookie(-name=>'session');
print "value1: $session{value1}\n";
print "value2: $session{value2}\n";

value1: something
value2: else

To try and duplicate this in PHP, I first examined the data in the
cookie that was set by perl:

So when I set the cookie in php I did:

Obviously this doesn't work...
%session just results in a single value of
"value1&something&value2&else" rather than a hash.

I also tried using Associative Arrays as they are the closest to the
Perl Hash that I could find.
$session[value1] = "something";
$session[value2] = "else";
The cookie then has the value "Array"
Any suggestions...ideally I don't want to have to change anything in
the perl scripts, I just want to retire them as PHP replacements are
completed. The page that sets the cookie is the first page (obviously)
and so would take the pressure off getting the other pages done in PHP.

PHP General Mailing List (
To unsubscribe, visit:

Reply via email to