Perl -> PHP question
| From: | Tom Woody | Date: | Thu, 24 Oct 2002 19:55:14 +0000 |
| Subject: | Perl -> PHP question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-121344@lists.php.net to get a copy of this message | ||
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";
CGI::Cookie(-name=>'session',-value=>%session);
In another perl script:
use CGI;
$query = CGI->new();
%session = $query->cookie(-name=>'session');
print "value1: $session{value1}\n";
print "value2: $session{value2}\n";
Output:
value1: something
value2: else
To try and duplicate this in PHP, I first examined the data in the
cookie that was set by perl:
value1&something&value2&else
So when I set the cookie in php I did:
setcookie('session','value1&something&value2&else');
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";
setcookie('session',$session);
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.
--
Tom Woody
Systems Administrator
NationWide Flood Research, Inc.
phone: 214-631-0400 x209
fax: 214-631-0800
Don't throw your computer out the window,
throw the Windows out of your computer!