0

Im using CGI::Session to store session data from CGI::Application (specifically i'm using CGI::Session through the CGI::Application::Plugin::Session module). In one of my application modes I do this:

    my $self = shift;
    # Get CGI query object
    my $q = $self->query();
    $self->session->save_param($q);

To save my parameters to the session data however on retrieving them using $self->session->param('user') I find that only the user parameter contains any data even though other parameters are being sent server side and are accessible through $q->param() the user parameter retrieved from the session is an array of the parameters, however i would expect that $self->session->param('user') would return a single string with the contents of the parameter 'user'.
Is this behavior expected?
If so why?

Euan Rochester
  • 183
  • 1
  • 8
  • 1
    Can you show us what the data key/value pairs? – Len Jaffe Dec 06 '12 at 21:44
  • What does a Data::Dumper output of your `$self->session` look like? How can it even save the CGI object at all...? – simbabque Dec 07 '12 at 08:12
  • It would also be helpful to see a Dump of $q and/or one of the output from $q->param() – RickF Dec 07 '12 at 14:59
  • I'm fairly new to perl and didn't know that there was any way to dump data, so thanks for that. After looking at the dump i then checked form that was sending the parameters, and saw that there were two fields called 'user', now I feel rather stupid, although that isn't what i thought would have happened from that mistake. – Euan Rochester Dec 07 '12 at 17:29
  • That happens. It's a lot more fun if you put all the params in a hash with `$q->Vars` and there are several fields with the same name, they end up in one string, concatenated with a `\0` char. Great, right? – simbabque Dec 08 '12 at 13:27

1 Answers1

0

I'm not sure I understand exactly what you mean, but this looks weird. You're not doing what the CGI::Session doc says you should. You can't just save the CGI object. You need to store each param individually.

# Storing data in the session:
$session->param('f_name', 'Sherzod');

If you want to just store all the CGI params in your Session, do it like this:

# $q := CGI object
# $session := CGI::Session object

$session->param('foo', $q->param('foo'));
$session->param('bar', $q->param('bar'));

Or you might even do it like this for all of them:

foreach my $key ($q->param) {
  $session->param($key, $q->param($key));
}
simbabque
  • 53,749
  • 8
  • 73
  • 136
  • Actually the CGI::Session doc does include the save_param method which is supposed to be "the same as calling param($name, $value) for every single query parameter returned by $query->param()". I haven't dug into the code yet, but I suspect that the CGI:App query object isn't doing the right thing with its param() method. – RickF Dec 07 '12 at 14:48