Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to get a cookie, split the 'sessionID' value field for a user/pass combo. When I print out cookieString it it empty (and it also unable to authenticate the user). The cookie is on the computer, and is in the format $user%7C$pass (I assume %7C is the char code for '|'). Here's the code:

if ($q->cookie('sessionID')) { my $sessionID = $q->cookie('sessionID'); $cookieString = $sessionID; ($submitted_username, $submitted_password) = split('|', $sessi +onID); } else { $submitted_username = $q->param('username'); $submitted_password = $q->param('password'); }

Can anyone tell where the error is?

Replies are listed 'Best First'.
Re: Problems grabbing cookie
by Cody Pendant (Prior) on Jun 25, 2003 at 10:42 UTC
    One obvious problem is that | has a special meaning in regexes, and the first argument to split is a regex, not a simple character. So you're going to want to split('\|',$sessionID) instead.

    And I don't know what's happening with your cookie, but I think you should unambiguously print out "here is the contents of the session ID cookie: $q->cookie('sessionID')" to see what's in there.

    Is it blank, is it undefined, is it whitespace, what is it? You have to figure out what you've really got in there because it seems you've got something.



    “Every bit of code is either naturally related to the problem at hand, or else it's an accidental side effect of the fact that you happened to solve the problem using a digital computer.”
    M-J D
Re: Problems grabbing cookie
by dataDrone (Acolyte) on Jun 25, 2003 at 04:53 UTC
    I'm a little confused here.... Why would the data in the Cookie get decoded for you automatically? Shouldn't you be looking to split on /%7C/ ? Of course that will only help you once you figure out why the Cookie is empty. I'm having a similar perplexing problem accepting cookies using my LWP user agent on Windows, while the same code runs fine on Linux. Perl 5.8 vs. 5.6.1 and I'm about at the point of downgrading to 5.6.1 on the windows box for code compatability. Argh!