Welcome to WebmasterWorld Guest from

Forum Moderators: coopster & jatar k & phranque

Message Too Old, No Replies

perl and CGI::Session

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

New User

5+ Year Member

joined:May 31, 2011
posts: 4
votes: 0


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.

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

Senior Member

WebmasterWorld Senior Member 5+ Year Member

joined:May 31, 2008
votes: 0

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 June 7, 2011 (gmt 0)


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

joined:Aug 10, 2004
votes: 96

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

New User

5+ Year Member

joined:May 31, 2011
posts: 4
votes: 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.


Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members