http://qs321.pair.com?node_id=369109

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

Hello all. Well, I'm working on login/session tracking and decided to use CGI::Session. I'm working in a windows enviroment and seem to be generating some problems getting the initial session started (hence I'm very inexperienced). Anyways, here is my code along with the errors that are generated when I try to run it.
use strict; use CGI qw(:standard); use CGI::Session; my $cgi = new CGI(); my $session = new CGI::Session(undef, undef, {Directory=>'\tmp'});
I get this error:
Can't locate DB_File.pm in @INC (@INC contains: C:/Perl/lib C:/Perl/si +te/lib .) at C:/Perl/site/lib/CGI/Session/DB_File.pm line 12. BEGIN failed--compilation aborted at C:/Perl/site/lib/CGI/Session/DB_F +ile.pm lin e 12.
I've also trying running it as
my $session = new CGI::Session("driver:FILE", undef, Directory=>File:: +Spec->tmpdir);
and had the same errors. I have File::Spec installed and I have created the directory /tmp. What am I missing here or not understanding? Thanks.

Replies are listed 'Best First'.
Re: CGI Session
by Abigail-II (Bishop) on Jun 23, 2004 at 16:48 UTC
    Just as the error message says, you don't have the module DB_File installed, or not properly installed. It seems to be a requirement for the CGI::Session module that you are using.

    Abigail

      I;m sorry I thought that I had installed that. I must have installed the wrong thing. Thanks for your help.
      Ok, now I'm getting this error: <code> (in cleanup) could not flush: Couldn't store ab4a75f8bddea52a28b08e0880a 41d41 into \tmp\cgisess_ab4a75f8bddea52a28b08e0880a41d41: No such file or direct ory at login.cgi line 0 <code> which seems to undicate I havn't created the direcotry. But I have the direcotry /tmp created so I'm curious what the problem is here. This directory: cgisess_ab4a75f8bddea52a28b08e0880a41d41 is supposed to be created inside of /tmp, correct? (to keep track of the session of that particular user)
        /tmp is an unlikely directory to have on Windows. Make sure there is a \tmp on the same drive as the web site (c:\tmp or d:\tmp) and that it is writable by the web server.
      Well, here is my complete code that is generating this error:
      use Data::Dumper; use CGI::Session; use CGI; my $cgi = new CGI; my $session = new CGI::Session(undef, $cgi, {Directory=>"\tmp" +}); $cookie = $cgi->cookie(CGISESSID => $session->id ); print $cgi->header(-cookie=>$cookie);
      With New error:
      (in cleanup) could not flush: Couldn't store 4206b0c8bba60b524 +6ced512c58 f5481 into mp\cgisess_4206b0c8bba60b5246ced512c58f5481: Invalid a +rgument at login.cgi line 0
      It seems like it won't create a session basically which I'm not sure why. I've searched the net and everywhere else and havn't found anyone with a similar problem (except one German site I couldn't read hehe). Any ideas? I'm going nuts trying to figure this out.

        \t inside doulbe quotes becomes a tab. Use "/tmp" instead. Where in your file system did you create the tmp folder?


        ___________
        Eric Hodges

        As was mentioned above, you have to give it a valid directory path. \tmp is probably not a valid directory path. For example, if you want your session files stored in a directory called SESSION located in the root of your C drive, make the directory there and use:

        my $session = new CGI::Session(undef, $cgi, {Directory=>"C:\\SESSION"});    
        

        Eric put his finger on it - \t within double-quotes is a tab. (If you look closely at the error message, you'll see blank space -- the tab -- where the "\t" should be.) Change your code to this:

        my $session = new CGI::Session(undef, $cgi, {Directory=>'\tmp'});

        and try again.

        Wally Hartshorn