Welcome to WebmasterWorld Guest from 54.146.171.44

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

perl and CGI::Session

   
7:44 pm on Jun 6, 2011 (gmt 0)



Hi,

I'm trying to use the CGI:Session module to handle session data and I must be doing something very daft as I just cant seem to generate a session id to add to the query strings I'm generating further on in the script.

I've looked at the cpan tutorial and it looks to me like the following code should generate the session strings i need.

use CGI::Session;

$session = new CGI::Session("driver:File",undef,{'Directory'=>"/tmp"});

$html_session = $session->id();

Instead I get the dreaded 500 error and the apache log file contains:

main.pl: Can't call method "id" on an undefined value at C:/wwwroot/cgi-bin/main.pl line 59

Any help would be greatly appreciated.

Thanks
7:53 pm on Jun 6, 2011 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Try calling CGI::Session->errstr() after you initialize the object. CGI::Session's new() will return undef if an error occurs, so you'll have to check for that, like

if(my $session = CGI::Session->new(...)) {
... normal code goes here
}
else {
print CGI::Session->errstr();
}


Of course that assumes that you've printed the http headers before this. Otherwise, just add them before printing the errstr()
12:18 am on Jun 7, 2011 (gmt 0)

WebmasterWorld Administrator phranque is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month



does the server have write access to the /tmp directory?
8:06 am on Jun 7, 2011 (gmt 0)



Thanks for the help, once I could see the error returned it was fairly obvious what I'd done - I hadn't installed the CGI::Sessionb module properly and there was a driver file missing.

Thanks