homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

perl and CGI::Session

Msg#: 4322595 posted 7:44 pm on Jun 6, 2011 (gmt 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.




WebmasterWorld Senior Member 5+ Year Member

Msg#: 4322595 posted 7:53 pm on Jun 6, 2011 (gmt 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()


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

Msg#: 4322595 posted 12:18 am on Jun 7, 2011 (gmt 0)

does the server have write access to the /tmp directory?


Msg#: 4322595 posted 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.


Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved